From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Boolean functions accepts numeric values..

Solved!
Go to solution

I recently came to know that all Boolean functions accept numeric values as well. But what is the purpose of it?

I found the Boolean functions outputting some random values while inputting numeric values..

 

Thank you!!

 

 

Best Regards,

Rashme SR

0 Kudos
Message 1 of 8
(3,409 Views)

The definition of a bool is x != 0, so that's what the function should equate to.

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 2 of 8
(3,399 Views)

Hi Rashme,

 

But what is the purpose of it?

The purpose is to apply boolean functions to integer values.

 

Instead of scalar booleans you can put 8/16/32/64 bits in an integer value and you can apply a boolean function to the whole integer (and all it's bits) at once.

Quite handy once you learn such stuff (when programming µCs at the assembler level)!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 3 of 8
(3,392 Views)

Ah, i misunderstood. Gerd is spot on. If, e.g. you want to know if the 4th bit is set, you can AND with 8 and compare to 0. If 0 it wasn't set, else it was. Now how is that beneficial? Many protocols just bits as flags, e.g. Intermec uses a 32 bit integer to set all relays in a module and thus you need to filter and set bits with AND and OR to do it efficiently.

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 4 of 8
(3,381 Views)

Another common use case is x AND 1 to see if a number is even/odd.

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 5 of 8
(3,372 Views)

I dont understand clearly. Can you please attach an example?

0 Kudos
Message 6 of 8
(3,366 Views)
Solution
Accepted by topic author srrashme

@srrashme wrote:

I dont understand clearly. Can you please attach an example?


What do you not understand?

 

When boolean logic is used on integers, the logic is done on a per bit basis.  I do this all the time for encoding and decoding data from specific protocols (some more wild than others).  This is also needed for many data checks (like a CRC or Reed Solomon) and for encryption (AES, DES, 3DES).


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 7 of 8
(3,347 Views)

Thank you so much.. finally i understood.. Doing binary calculations using numeric controls.. Its awesome

 

Regards,

Rashme SR

0 Kudos
Message 8 of 8
(3,329 Views)