+ 2

What does the vertical line( | ) mean in PYTHON?

for example: why 10|20 =30, and 10|10 =10?

6th Jun 2018, 10:05 AM
Zhenia Bereza
Zhenia Bereza - avatar
5 Answers
+ 23
(|) is a Bitwise OR operator if any one or both of the bits is 1, it results 1 if both the bits are zero 0, it results in 0 10|20 = 30 Binary Decimal 0000 1010 10 | 0001 0100 20 -------------------------------------- 0001 1110 30 1|0 = 1 1&0 = 0 1|1 = 1 1&1 = 1 0|0 = 0 0&0 = 0 Check out the lesson 👇 https://www.sololearn.com/learn/4073/?ref=app
6th Jun 2018, 10:47 AM
🌛DT🌜
🌛DT🌜 - avatar
+ 28
Markus Kaleton Yes xor (^) 1^1 = 0 0^0 = 0 1^0 = 1 0^1 = 1 when the bits of operands on both side of ^ operators are same then the result is 0 if different result is 1... here's the lesson 👇 https://www.sololearn.com/learn/4074/?ref=app
6th Jun 2018, 12:29 PM
🌛DT🌜
🌛DT🌜 - avatar
+ 1
bitwise or
6th Jun 2018, 10:08 AM
Venkat
Venkat - avatar
0
🌛DT🌜 followup question. does the bitwise operation do xor? 0+0=0, 1+0=1, 0+1=1, 1+1=0?
6th Jun 2018, 12:21 PM
Markus Kaleton
Markus Kaleton - avatar
0
cheers
6th Jun 2018, 12:34 PM
Markus Kaleton
Markus Kaleton - avatar