What does '|' mean? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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