LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

any good way to combine 32 boolean bits to a number?

I have 32 boolean inputs, and want to combine these 32 boolean to an unsigned number. Is there any good way other than "joint number" or "logic shift & logic and"?

 

input:

32 boolean: boolean 0, boolean 1, ,,, boolean 31

 

output:

32-bit unsigned number: boolean 0 is bit 0, boolean 1 is bit 1,,,,, boolean 31 is bit 31.

 

Thanks.

0 Kudos
Message 1 of 12
(3,935 Views)

Boolean Array to Number

 

It's in the Boolean palette.

Message 2 of 12
(3,932 Views)

Does the following code snippet help? By the way, 32 booleans is a lot, so I'd manage them with a cluster if I were you. That will reduce the possibility of errors (wiring boolean 8 to boolean 9's positions, etc...).

 

Boolean Array to Number.png

Message 3 of 12
(3,925 Views)

Sorry, i didn't say it clearly -

 

The input is an array of double with each element having boolean value.

 

What I can think of is to convert each element to be unsigned 32-bit, left shift each element, and add all elements.

0 Kudos
Message 4 of 12
(3,897 Views)

"array of double" meaning a 2-D array or an array of double precision numbers?

 

Maybe you could post a picture or your code?

0 Kudos
Message 5 of 12
(3,891 Views)

@MileP wrote:

Sorry, i didn't say it clearly -

 

The input is an array of double with each element having boolean value.

 

What I can think of is to convert each element to be unsigned 32-bit, left shift each element, and add all elements.


I will assume each float can be either "0" or "1".

 

Yes you could use that approach but you would have to reverse your array such that the first element is weighted as the "ones-bit".

 

There are many other ways to do it. There are operators on the data manipulation palette that will arithmetic shift left, right rotate join split etc.

 

Have fun,

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 6 of 12
(3,889 Views)

Ben is nudging you towards a mention in the Rube Goldberg thread, which I enjoy as much as the next guy.  Ravens had it right though, you just need a small tweak to get the Boolean Array from the DBL array.  Assuming any non-zero value is TRUE, you can simply do this:

 

DBLArrayToU32.png

 

Bonus version for the FP math junkies.

 

 

Message 7 of 12
(3,871 Views)

@Darin.K wrote:

Ben is nudging you towards a mention in the Rube Goldberg thread, which I enjoy as much as the next guy.  Ravens had it right though, you just need a small tweak to get the Boolean Array from the DBL array.  Assuming any non-zero value is TRUE, you can simply do this:

 

DBLArrayToU32.png

 

Bonus version for the FP math junkies.

 

 


Telling someone there IS a bucket of Truth is not the same a pushing (or nudging) them in.

 

The questions started to go down the path of ".... this is how I would have done it in C ...." so I was making sure they know where to find the functions in LV.

 

Take care,

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 8 of 12
(3,865 Views)

 

 

 


@Ben wrote:

 

Telling someone there IS a bucket of Truth is not the same a pushing (or nudging) them in.

 

The questions started to go down the path of ".... this is how I would have done it in C ...." so I was making sure they know where to find the functions in LV.

 


Giving them enough rope wire, now I see...

 

0 Kudos
Message 9 of 12
(3,853 Views)
Darin, Why the *(-2) instead of a negate for the lower limit epsilon? Thanks, Randy
Message 10 of 12
(3,842 Views)