[025] 비트 연산자 이해하기(&, |, ~, ^, >>, <<)

책 내용에 대한 무단배포 방지를 위해 최소한으로 정리

bit1 = 0x61 # 0110 0001
bit2 = 0x62 # 0110 0010

print(hex(bit1&bit2)) # 0110 0000 -> 0x60
print(hex(bit1|bit2)) # 0110 0011 -> 0x63
print(hex(bit1^bit2)) # 0000 0011 -> 0x03
print(hex(bit1 >> 1)) # 0011 0000 -> 0x30
print(hex(bit1 << 2)) # 1 1000 0100 -> 0x184

Comments