0
What is the use of ^ in this code and how it works?
print(4^9) print(5^9) output: 13 12
3 Réponses
+ 2
A = [1, 0, 1, 0]
B = [1, 1, 0, 0]
print('A', '\t', 'B', '\tA^B')
for i in range(4):
print(A[i], '\t', B[i], '\t', A[i]^B[i])
print('\n==================\n')
print(f'{4^9 = }')
print(bin(4), bin(9), bin(13))
a = [0, 1, 0, 0]
b = [1, 0, 0, 1]
c = []
print('a', '\t', 'b', '\t', 'c')
for i in range(4):
print(a[i], '\t', b[i], '\t', a[i]^b[i])
c.append(a[i]^b[i])
print(f"{c = }")
print(f"{int(''.join(list(map(str, c))), 2) = }")
print('\n==================\n')
print(f'{5^9 = }')
print(bin(5), bin(9), bin(12))
a = [0, 1, 0, 1]
b = [1, 0, 0, 1]
c = []
print('a', '\t', 'b', '\t', 'c')
for i in range(4):
print(a[i], '\t', b[i], '\t', a[i]^b[i])
c.append(a[i]^b[i])
print(f"{c = }")
print(f"{int(''.join(list(map(str, c))), 2) = }")
0
bitwise xor?
A = [1, 0, 1, 0]
B = [1, 1, 0, 0]
for i in range(4):
print(A[i], B[i], A[i]^B[i])