# & operators into if instrucion

**URL:** https://discourse.nodered.org/t/operators-into-if-instrucion/10171
**Category:** General
**Created:** [15 April 2019 13:24 UTC](https://discourse.nodered.org/t/operators-into-if-instrucion/10171 "2019-04-15T13:24:10Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![GiovanniG](https://avatars.discourse-cdn.com/v4/letter/g/ecd19e/32.png) [@GiovanniG](https://discourse.nodered.org/u/GiovanniG)
#### Post date: [15 April 2019 13:24 UTC](https://discourse.nodered.org/t/operators-into-if-instrucion/10171/1 "2019-04-15T13:24:10Z")

</div>

Hi mates, after a couple of hours I figured out what didn't work. For me it's something illogic, and I'm afraid to loose in future more time on something similar:  
Supposing we have a byte IO1\_B, the result of the read of I/O chip connected to some lines. I need to test the first bit, ad do something according to it  
Why if (IO1\_B & 0x1) gives a proper result  
and if (IO1\_B & 0x1 == 0) or if (IO1\_B & 0x1 === 0) doesn't give the opposite result? where is the problem here? Should I writ if (IO1\_B & 0x1 === false)? or if ((IO1\_B & 0x1) === 0) ?  
Thank you

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [15 April 2019 13:35 UTC](https://discourse.nodered.org/t/operators-into-if-instrucion/10171/2 "2019-04-15T13:35:38Z")

</div>

try a google search using `javascrippt multiple comparisons`

---

<div class="post-metadata">

### Author: ![GiovanniG](https://avatars.discourse-cdn.com/v4/letter/g/ecd19e/32.png) [@GiovanniG](https://discourse.nodered.org/u/GiovanniG)
#### Post date: [15 April 2019 21:48 UTC](https://discourse.nodered.org/t/operators-into-if-instrucion/10171/3 "2019-04-15T21:48:11Z")

</div>

Thank you, unfortunately not easy to find exactly my case..

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [15 April 2019 21:57 UTC](https://discourse.nodered.org/t/operators-into-if-instrucion/10171/4 "2019-04-15T21:57:28Z")

</div>

Bitwise operators return a number.

You can get to grips with them [Here](https://www.w3schools.com/js/js_bitwise.asp)

---

<div class="post-metadata">

### Author: ![GiovanniG](https://avatars.discourse-cdn.com/v4/letter/g/ecd19e/32.png) [@GiovanniG](https://discourse.nodered.org/u/GiovanniG)
#### Post date: [15 April 2019 22:02 UTC](https://discourse.nodered.org/t/operators-into-if-instrucion/10171/5 "2019-04-15T22:02:14Z")

</div>

thanks for your answer,, why 0 is not a number?  
(IO1\_B & 0x1) works, if the first bit of IO1\_B is 1 i can execute something, or better.. my goal is to check if it is 0, so I use the "else" command.

now why (IO1\_B & 0x1 == 0) doesn't work?

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [15 April 2019 22:16 UTC](https://discourse.nodered.org/t/operators-into-if-instrucion/10171/6 "2019-04-15T22:16:40Z")

</div>

Operator precidance.  
Try `((IO1_B & 0x1) == 0)`

---

<div class="post-metadata">

### Author: ![GiovanniG](https://avatars.discourse-cdn.com/v4/letter/g/ecd19e/32.png) [@GiovanniG](https://discourse.nodered.org/u/GiovanniG)
#### Post date: [16 April 2019 18:32 UTC](https://discourse.nodered.org/t/operators-into-if-instrucion/10171/7 "2019-04-16T18:32:14Z")

</div>

thank you, now it's more clear how javascript works. In C the precedence is on operators, not on the =, there is no sense to put priority on =

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [16 April 2019 20:12 UTC](https://discourse.nodered.org/t/operators-into-if-instrucion/10171/8 "2019-04-16T20:12:40Z")

</div>

You right however...  
== is an operator.  
= Is assignment.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [16 April 2019 21:21 UTC](https://discourse.nodered.org/t/operators-into-if-instrucion/10171/9 "2019-04-16T21:21:45Z")

</div>

I am not absolutely certain but I think you will find that C is exactly the same as javascript in this case, so  
`a & b == 0`  
will be interpreted as  
`a & (b == 0)`  
in both languages.

---

<div class="post-metadata">

### Author: ![GiovanniG](https://avatars.discourse-cdn.com/v4/letter/g/ecd19e/32.png) [@GiovanniG](https://discourse.nodered.org/u/GiovanniG)
#### Post date: [20 April 2019 11:54 UTC](https://discourse.nodered.org/t/operators-into-if-instrucion/10171/10 "2019-04-20T11:54:28Z")

</div>

Thank you for help! SInce now I always had the feeling that compiler will do everything before == and after it, it has much more logic, by the way it could be just a "good" compiler, to me )  
I've got the lesson to always use pharentesis, it will make me much less crazy )

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [20 April 2019 12:40 UTC](https://discourse.nodered.org/t/operators-into-if-instrucion/10171/11 "2019-04-20T12:40:25Z")

</div>

Consider what you might expect if you used  
`a == 0 & b == 0`  
You might expect it to interpret this as  
`(a==0) & (b==0)`  
In which case `==` has to be performed before `&`

---

<div class="post-metadata">

### Author: ![GiovanniG](https://avatars.discourse-cdn.com/v4/letter/g/ecd19e/32.png) [@GiovanniG](https://discourse.nodered.org/u/GiovanniG)
#### Post date: [20 April 2019 12:51 UTC](https://discourse.nodered.org/t/operators-into-if-instrucion/10171/12 "2019-04-20T12:51:43Z")

</div>

I understand, I got the reason. Good bless pharentesis
