cancel
Showing results for 
Search instead for 
Did you mean: 

Boolean functions accepts numeric values..

SOLVED
Rashme_SR
Member
Solved!

Boolean functions accepts numeric values..

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

7 REPLIES 7
Yamaeda
Proven Zealot

Re: Boolean functions accepts numeric values..

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
GerdW
Knight of NI

Re: Boolean functions accepts numeric values..

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
Yamaeda
Proven Zealot

Re: Boolean functions accepts numeric values..

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
Yamaeda
Proven Zealot

Re: Boolean functions accepts numeric values..

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
Rashme_SR
Member

Re: Boolean functions accepts numeric values..

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

crossrulz
Knight of NI
Solution

Re: Boolean functions accepts numeric values..

Message contains an image Message contains an attachment

@Rashme_SR 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).



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
Rashme_SR
Member

Re: Boolean functions accepts numeric values..

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

 

Regards,

Rashme SR