+ 4
print (5|3) Why output is 7?
8 Réponses
+ 13
0101 -> 5 in binary
0011 -> 3 in binary
--------
0111 -> 7 in binary
It is a bitwise OR operation.
+ 5
am telling in c and cpp but concepts are same in python also| (bitwise OR) in C or C++ takes two numbers as operands and does OR on every bit of two numbers. The result of OR is 1 if any of the two bits is 1.
a = 10 = 1010 (Binary) b = 4 = 0100 (Binary a | b = 1010 | 0100 = 1110 = 14 (Decimal)
a = 5, b = 9;
a = 5(00000101), b = 9(00001001)
print("a|b = %d\n", a | b);
+ 3
Coz It uses binary coded decimal (BCD) OR logic Boolean operator
+ 2
It is called Bitwise OR.
It is binary representation.
It return 1 if any one value is 1.
Here 5|3
In binary
0000 0101 =5
0000 0011 =3
------------
0000 0111 = 7
https://www.sololearn.com/learn/4073/?ref=app
+ 2
| stands for Bitwise OR . The binay value of 5 is 101 and the binary value of 3 is 011
1 or 0 is 1
0 or 1 is 1
1 or 1 is 1
0 or 0 is 0
So compare each binary value of 5 and 3 the result is 111 .So the binary value of 7 is 111
+ 2
OR operator used..here i.e. + ...
Here.., (3)10 =(?)2
= division remainder
= 3/2 =》1 1
= 1/2 =》0 1
Hence, in Binary (3)10 = 》(11)2 or (011)2. ; (i)
And, then...(5)10 =(?)2
~...similarly as above..it gives
=》 (101)2. ; (ii)
Adding... i and ii ;
011
+101
_______
1000
_______
..
And 8 =(1000)..! in binary
Hope it helps..!!🙋♂️
+ 1
Thx. As newbie I was just puzzled with this in the "Play".