0
#Python "What is this '|'?"
3 Answers
+ 4
bitwise or, google itđ
+ 3
Bitwise OR:
Compares each pair of corresponding bits from two bit patterns of equal lenght.
The result in each position is 0 if both bits are 0, otherwise is 1.
For example:
(7|5)
0111 (Decimal 7)
OR
0101 (Decimal 5)
= 0111 (Decimal 7)
(3|6)
0011 (Decimal 3)
OR
0110 (Decimal 6)
= 0111 (Decimal 7)
+ 1
It is bitwise OR, which perform operation on bits of numbers.
Its functioning can be understood from its truth table that seems to be like this:
x. y. x|y
0. 0. 0
0. 1. 1
1. 0. 1
1. 1. 1
when u say 1|5 1 is written as 00001 and 5 as 00101. so when we apply or operation starting from left we have 1 and 1 so returns 1
then 0 and 0 returns 0
0 and 1 returns 1
and so for every 0 to 0 therefore
the end result was like
00101 which is 5 đ