+ 1

Can someone explain me this bit operation code

n1 = input("Binary n1: ") n2 = input("Binary n2: ") print() n1 = int(n1, 2) n2 = int(n2, 2) bit_or = n1 | n2 bit_and = n1 & n2 bit_xor = n1 ^ n2 bit_or = bin(bit_or) bit_and = bin(bit_and) bit_xor = bin(bit_xor) print(" n1: %10s" % bin(n1)) print(" n2: %10s" % bin(n2)) print(" ------------") print(" OR: %10s" % bit_or) print("AND: %10s" % bit_and) print("XOR: %10s" % bit_xor)

14th May 2020, 11:07 AM
harshita jain
harshita jain - avatar
3 odpowiedzi
+ 3
It takes two binary numbers ,say for example 0b111 0b111 Converts them into integers 7 7 Then perform binary operations like binary or ,and,XOR on them which results in 7 7 0 and then converts these integers back into binary numbers 0b111 0b111 0b0
14th May 2020, 12:04 PM
Abhay
Abhay - avatar
+ 1
14th May 2020, 12:05 PM
XXX
XXX - avatar