+ 1
why the output is 16?
a = 1 | 5 b = 10 | 1 print (a + b)
4 Answers
+ 8
| is binary OR operator. Let's see what's the value of a and b when assigning them,
a=1|5:
1 in binary is 0001
5 in binary is 0101
1 | 5 = 0101
So a=0101 => a=5
b=10|1:
10 in binary is 1010
1 in binary is 0001
10 | 1 = 1011
So b=1011 => a=11
a+b=11+5 => a+b=16
And that's how the output is 16
+ 1
thnx, like for your Syntax.
+ 1
Rishi, it was a good explanation. Helped me too š¤
+ 1
Happy to helpš¤