LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Boolean array to number

Solved!
Go to solution

I'm not sure if this has ever been brought up before, but if so, here it is again.  Lets say I have a Boolean Array shown with 8 elements arranged horizontally.  When I read it, I usually read left to right, meaning the MSB is on the left and the LSB is on the right.  However, if I use the Boolean Array to Number funtion, this function reads right to left.  Same for the Number to Boolean Array function,  It will form the array from right to left.  This goes against normal boolean reading habits.  I know this isn't a bug because it was probably meant to operate as such.  The VI shown below illustrates what I mean.  Three questions:

 

Why is it done this way?

 

Why not make the functions configurable to read in either direction?

 

The term Big Endian / Little Endian applies to byte order in a 16-bit word broken into two bytes.  Does it also apply to bit order in a U8?

 

Here is the VI:

 

BoolArrayToNumber.png

- tbob

Inventor of the WORM Global
0 Kudos
Message 1 of 5
(11,516 Views)

endian-ness refers to byte order, not bit order.

binary formatted numbers have the lowest bit on the right. (same as decimal, hex, etc)

Arrays have element zero on the left. (180 degrees different from above formats)

 

To flip the bits in an U8, easiest would be a lookup table, it is only 256 bytes!

 

 

0 Kudos
Message 2 of 5
(11,511 Views)

@tbob wrote:

 

Why is it done this way?

 

Why not make the functions configurable to read in either direction?

 

The term Big Endian / Little Endian applies to byte order in a 16-bit word broken into two bytes.  Does it also apply to bit order in a U8?


Bit ordering is (almost) always consistent.  The lowest order bit is bit 0.  In LabVIEW's array representation, index 0 is on the left, so you see it what you consider to be "backwards."  If this were changed, or configurable, it would be confusing when you feed only a few bits of an array into boolean array to numeric.  I expect that if I build two TRUE values into an array and then convert that to a numeric, that those two TRUE values will be in the low-order bits and the rest will be padded with zeros; anything else would puzzle me.

0 Kudos
Message 3 of 5
(11,505 Views)
Solution
Accepted by topic author tbob

Type Cast man escapes from his cage again!

 

BooleanArrayTypeCast.png

 

I always use 4.x mode when I want "human readable" bit arrays.

Message 4 of 5
(11,484 Views)

My midset at the time I wrote this was on bytes and converting U8s to boolean and back again.  Didn't think of correlating array index to bit position.  But Darin K came through with the human readable solution.  Of course, reversing the 1D array worked for me also, but it only holds to U8s, U16s, etc.  Thanx Darin.

 

- tbob

Inventor of the WORM Global
0 Kudos
Message 5 of 5
(11,449 Views)