0

I have an object that I need to compare some attributes of and I can't explain what is going on, but the following is the output of my VS code debugger (I added '=' before each output)

(0 > 55000 | 150 > 280)
=False # expected
250>150
=True # expected
True & False 
=False # expected
(250>150 & (0 > 55000 | 150 > 280))
=True # what????
DanGoodrick
  • 2,410
  • 5
  • 25
  • 48

3 Answers3

2

For numbers, & is "bitwise and" and | is "bitwise or". These operators have higher precedence than comparison operators like > and <.

150 & (0 > 55000 | 150 > 280) == 150 & 0 == 0 then 150>0 is True.

DanGoodrick
  • 2,410
  • 5
  • 25
  • 48
Yu Cheng
  • 91
  • 3
0

You're using binary bitwise operators & and |. You should be using boolean operators and and or.

Yuri Sh
  • 569
  • 7
0

| and & are bit operators. bit operators have higher priority better than comparison operator. you should change '|' to "or"and '&' to "and"