0

What is the use of ^ in this code and how it works?

print(4^9) print(5^9) output: 13 12

3rd Oct 2022, 11:23 AM
Shantanu
Shantanu - avatar
3 Respuestas
3rd Oct 2022, 4:30 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 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) = }")
3rd Oct 2022, 1:10 PM
Bob_Li
Bob_Li - avatar
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])
3rd Oct 2022, 11:46 AM
Bob_Li
Bob_Li - avatar