+ 3

Bitwise pipe operator

How does print (5|3) return 7?

9th Aug 2020, 12:01 PM
Mike H
Mike H - avatar
4 Answers
+ 3
Loma , I'm sorry but that isn't true... Bitwise or operator performs bitwise or operation, not addition (that's why it is called bitwise or ;) ) So it is 0101 Or 0011 = ------------ 0111 = 7 By the way 0101 + 0011 ----------- 1000 = 8
9th Aug 2020, 6:23 PM
G B
G B - avatar
+ 9
5 binary representation is 0b101 and for 3 it is 0b011 and that is bitwise or operator which returns 1 if either bit is 1 else 0 ,so after calculation you get 0b111 whose representation in decimal is 7
9th Aug 2020, 12:20 PM
Abhay
Abhay - avatar
+ 4
G B you are right👍
10th Aug 2020, 4:22 PM
Butterfly 💞💕
Butterfly 💞💕 - avatar
+ 2
The bitwise inclusive or operator (|) compares each bit of its first operand to the corresponding bit of its second operand. If either bit is 1 output is 1 else 0
9th Aug 2020, 12:15 PM
Peter Parker
Peter Parker - avatar