+ 1

why the output is 16?

a = 1 | 5 b = 10 | 1 print (a + b)

6th Jan 2022, 9:14 AM
HamidReza
HamidReza - avatar
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
6th Jan 2022, 9:23 AM
Rishi
Rishi - avatar
+ 1
thnx, like for your Syntax.
6th Jan 2022, 9:24 AM
HamidReza
HamidReza - avatar
+ 1
Rishi, it was a good explanation. Helped me too šŸ¤—
6th Jan 2022, 9:43 AM
Krish
Krish - avatar
+ 1
Happy to helpšŸ¤—
6th Jan 2022, 2:51 PM
Rishi
Rishi - avatar