+ 2

A Why & how question

def f (m,n) return m|n print (f(10,20) why it is 30 ? how does it work ?

16th Jan 2018, 6:03 AM
MrFantastic
MrFantastic - avatar
2 Answers
+ 11
Just in case you didn't get @Petr Leliaev's explanation: Binary OR operation is performed based on the two numbers passed into the function. The two numbers are evaluated in binary format. OR 0|0 = 0 0|1 = 1 1|0 = 1 1|1 = 1 10 (decimal) is 1010 (binary). 20 (decimal) is 10100 (binary). 01010 10100 ---------- 11110 = 30 ----------
16th Jan 2018, 6:34 AM
Hatsy Rei
Hatsy Rei - avatar
+ 3
m=10=1010(2) n=20=10100(2) m|n = 11110(2)=30(10)
16th Jan 2018, 6:16 AM
Petr Leliaev
Petr Leliaev - avatar