LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

from byte to any number of bit representation of same number generically vi

Has anyone made a VI that can concatenate bit arrangements of irregular sizes (like 5 bits) together to form a byte array?

 

I have three 5 bit numbers that I want to put into two bytes in little endian order. Is there a a way to automatically split up the bits to just fit into the array?

 

What happens to the bit that is not accounted for within the 15 bits? 

0 Kudos
Message 1 of 5
(2,658 Views)

How do you currently have the 5-bit numbers stored?  U8?  Boolean Array?  String?



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 2 of 5
(2,653 Views)

U8 representation. Display format is binary, but not sure if that matters. 

0 Kudos
Message 3 of 5
(2,634 Views)

You can build an array of binary values, then do "Boolean Array to Number."  If you already have 3 5-element arrays, just append them.  The output is a 32-bit value with all the unused bits set to 0, so you can convert that to a U16 which will have your data in the low 15 bits and a 0 in the highest-order bit.

 

EDIT: Alternatively you can just do some bit math such as shown in this image:

3x5bit to U16.png

0 Kudos
Message 4 of 5
(2,623 Views)

I was trying to come up with something more generic, but it looks like nathand might have the best solution for your particular problem.  His code there will give you a U16.  If you need a btye array, you can use the split number and build array.



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 5 of 5
(2,613 Views)