0

What does '|' mean?

What function does that symbol do

20th Mar 2020, 12:56 PM
Abere Fejiro
Abere Fejiro - avatar
2 Answers
+ 5
| is "bitwise OR" operator. It compares all bits of operands. If either of the bit being compared is one then corresponding bit in resulting number is 1 ,otherwise 0. Example : print(5|2) 6 => 110b 2 => 010b 110b => 6 #decimal equivalent of binary 110b is 6 print(3|9) 3 => 0011b 9 => 1001b 1011b => 11 #decimal equivalent of binary 1011b is 11 There are some other use cases than just binary operations but google is your friend.
20th Mar 2020, 2:48 PM
šŸ‡®šŸ‡³OmkaršŸ•‰
šŸ‡®šŸ‡³OmkaršŸ•‰ - avatar
0
Ok i understand thank you So it compares the binary bits of the two decimal numbers using the OR operator
20th Mar 2020, 3:41 PM
Abere Fejiro
Abere Fejiro - avatar