# How do I achieve this in Node Red

**URL:** <https://discourse.nodered.org/t/how-do-i-achieve-this-in-node-red/32627>\
**Category:** General\
**Created:** [9 September 2020 07:42 UTC](https://discourse.nodered.org/t/how-do-i-achieve-this-in-node-red/32627 "2020-09-09T07:42:07Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![blob](https://avatars.discourse-cdn.com/v4/letter/b/ebca7d/32.png) [@blob](https://discourse.nodered.org/u/blob)\
**Post date:** [9 September 2020 07:42 UTC](https://discourse.nodered.org/t/how-do-i-achieve-this-in-node-red/32627/1 "2020-09-09T07:42:08Z")

</div>

Hello,

This may seem absolutely easy task for someone out there but I'm stuck on this one.

Scenario:  
I'm trying to achieve something in Node Red that has been done on Visual Basic.  
A very simple scenario which could be understood by seeing the images below -  
I have a combination of long integers in visual Basic which gives me zero or non zero values for certain combinations which when tried in Node Red with the same combinations doesn't give the desired results as those achieved in VB (Visual Basic)

This is what is has been done in VB

 ![VB](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/5/55fa7cd11f75f5c4a9ce96a81b700a05028c26b7.jpeg)

temp1, temp4, temp5, temp6 gives me zero, while  
temp2, temp3 gives me non zero values in VB But same is not achieved in Node Red.

Node Red screen

 ![Node1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/7/a755495861a288c4f2d0a087bf3bbaab57ee9ced.jpeg)

And the Result......

![Node2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/3/b3a007f7e5270541d2b392ecfceee0b27dd13ff0.jpeg)

Which should give me ZERO in Node Red (as this same combination in VB gives me zero) But I'm getting something else. How do I achieve this (result zero) ?

Also last question which is actually irrelevant here but someone from VB background may answer.

Why am I getting the non zero values for temp2 & temp3? can anyone explain please?

Thanks

---

<div class="post-metadata">

**Author:** ![greengolfer](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/greengolfer/32/28276_2.png) [@greengolfer](https://discourse.nodered.org/u/greengolfer)\
**Post date:** [9 September 2020 08:00 UTC](https://discourse.nodered.org/t/how-do-i-achieve-this-in-node-red/32627/2 "2020-09-09T08:00:07Z")

</div>

According to [https://www.w3schools.com/js/js\_bitwise.asp](https://www.w3schools.com/js/js_bitwise.asp) the bitwise comparison that you want to do is using & and not && in javascript.  
Have you tried with just one & ?

---

<div class="post-metadata">

**Author:** ![afelix](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/afelix/32/9743_2.png) [@afelix](https://discourse.nodered.org/u/afelix)\
**Post date:** [9 September 2020 08:10 UTC](https://discourse.nodered.org/t/how-do-i-achieve-this-in-node-red/32627/3 "2020-09-09T08:10:57Z")

</div>

Additionally, in JavaScript `||` and `&&` are boolean operators, so rather than bitwise you’re comparing them. There’s a large matrix somewhere out on the Internet explaining the specifics of boolean operators in JS per type and direction, but for bitwise you require the single character rather than double.  
So what you see in your debug is the output of boolean comparison rather than bitwise operation. Hope that helps.

---

<div class="post-metadata">

**Author:** ![blob](https://avatars.discourse-cdn.com/v4/letter/b/ebca7d/32.png) [@blob](https://discourse.nodered.org/u/blob)\
**Post date:** [9 September 2020 11:36 UTC](https://discourse.nodered.org/t/how-do-i-achieve-this-in-node-red/32627/4 "2020-09-09T11:36:39Z")

</div>

Using only one & for bitwise comparison is giving the desired result.  
Thank you all.  
But when i tried to use this in an if /else or if/esle if statement I'm getting this error.

![Node3](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/5/c5203a18591a413a5218124bcefccbb58af6021a.jpeg)  
 ![Node4](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/d/0ddb2209e3ac9018087ec3104c1eae3e2b5608e5.jpeg)

---

<div class="post-metadata">

**Author:** ![greengolfer](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/greengolfer/32/28276_2.png) [@greengolfer](https://discourse.nodered.org/u/greengolfer)\
**Post date:** [9 September 2020 11:48 UTC](https://discourse.nodered.org/t/how-do-i-achieve-this-in-node-red/32627/5 "2020-09-09T11:48:25Z")

</div>

You want to many & and now you want to many = !!  
Try removing one = 🙂

---

<div class="post-metadata">

**Author:** ![blob](https://avatars.discourse-cdn.com/v4/letter/b/ebca7d/32.png) [@blob](https://discourse.nodered.org/u/blob)\
**Post date:** [9 September 2020 11:55 UTC](https://discourse.nodered.org/t/how-do-i-achieve-this-in-node-red/32627/6 "2020-09-09T11:55:24Z")

</div>

Already tried with single = double == and === also but still problem

![Node5](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/d/2dafd5d97511ed4da12bce5380ac2dd24d862564.jpeg)

I think main problem is missing "," before statement which I fail to understand.

syntax is correct everything is correct despite this there is problem.

---

<div class="post-metadata">

**Author:** ![blob](https://avatars.discourse-cdn.com/v4/letter/b/ebca7d/32.png) [@blob](https://discourse.nodered.org/u/blob)\
**Post date:** [9 September 2020 12:04 UTC](https://discourse.nodered.org/t/how-do-i-achieve-this-in-node-red/32627/7 "2020-09-09T12:04:18Z")

</div>

Sorry to bother you.

Nabbed the culprit

The I in if else was capital - If should have been if

Thanks for your support.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [8 November 2020 12:04 UTC](https://discourse.nodered.org/t/how-do-i-achieve-this-in-node-red/32627/8 "2020-11-08T12:04:40Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
