Python incluye ejercicios 53
Tema: Aprender a usar XOR bit a bit ^.
Programa de análisis: 0 ^ 0 = 0; 0 ^ 1 = 1; 1 ^ 0 = 1; 1 ^ 1 = 0
Código fuente:
#!/usr/bin/python # -*- coding: UTF-8 -*- if __name__ == '__main__': a = 077 b = a ^ 3 print 'The a ^ 3 = %d' % b b ^= 7 print 'The a ^ b = %d' % b
La salida del ejemplo anterior es:
The a ^ 3 = 60 The a ^ b = 59