I want an explanation to this code: What is it "|" | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

I want an explanation to this code: What is it "|"

1|2 is 3 10|20 is 30 100|200 is 236

4th May 2017, 2:58 PM
Jean Fouby 🇨🇲
Jean Fouby 🇨🇲 - avatar
3 Answers
+ 24
It's bitwise OR operator. It converts both the operands to equivalent binary numbers and checks bit by bit. If any of the bit is 1, it'll give 1. 1|2 = 01 | 10 = 11 = 3 10|20 = 01010 | 10100 = 11110 = 30
4th May 2017, 3:30 PM
Shamima Yasmin
Shamima Yasmin - avatar
+ 3
For sets, it is the union operator (outputs all elements that are in A or in B or in both)
4th May 2017, 9:14 PM
Amaras A
Amaras A - avatar
+ 2
Thanks a lot :-)
4th May 2017, 10:41 PM
Jean Fouby 🇨🇲
Jean Fouby 🇨🇲 - avatar