ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Converting numeric array into boolean (bits)

Hello all,

I would be grateful for some advice regarding this problem.

I have a large array of 16bit unsigned data.  The data is composed from two different sources so I need to be able to retrieve the 16bits as two arrays of 8 bits for each position in the array.  For example, if the array were 100x100, the original data stream would have been 20000 bits long, I would have had 100x100 array of 8-bit unsigned integers followed by another 100x100 array of 8 bit unsigned integers.  When I read it into Labview, I need to read it as 16-bit in order to retrieve all of the data from the file.  What I need to do is read in this data and for each position in the array, separate the 16-bit values into the two 8-bit values then re-join so the first 8-bit value attaches to the 10,000th 8-bit value to make a new 16-bit value composed from the two different data sources.  I have tried indexing the array and converting each number to boolean but this takes far too long to be viable.  Is there a better way to do this?  Please ask if you need more explanation.

Thanks in advance,

Sarah
0 Kudos
Message 1 of 7
(3,914 Views)

I can't say that I really understand how you're getting the data, or which 2 bytes you're joining at each stage, but I would suggest you start by looking in the Advanced>>Data Manipulation palette (specifically Split Number and Join Numbers, which can operate on arrays as well).

If this doesn't help, I suggest you post your code with some example data, so that we can understand better.


___________________
Try to take over the world!
0 Kudos
Message 2 of 7
(3,910 Views)
Thanks for your response, the functions in that palette have helped greatly.  I now have one further question.  If I have an 8-bit integer but only want to use 4-bits (in this case, 4-bits contain debug data, 4-bits contain the output data), is there a function I can use?  I have used the split number function to break the original 16-bit integer down into 8-bit but this function does not take 8-bit data as an input so I cannot repeat the process.

Thanks again,

Sarah
0 Kudos
Message 3 of 7
(3,881 Views)
Hi Sarah,

you can use the AND primitive to mask the needed 4 bits.
If you need the upper 4 bits of an U8 you can use a divide by 16.

Oh, that reminds me of that good old Quotient&Remainder: just divide by 16. The remainder gives you the lower 4 bits, the quotient represents the upper 4 bits.


Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 4 of 7
(3,878 Views)
Forgive my ignorance but the AND function requires boolean inputs.  From my U8 number, how would I use this function?

Thanks for the advice.

Sarah
0 Kudos
Message 5 of 7
(3,871 Views)
If you look at the help for AND, you will see that it accepts numbers as well as booleans.  This applies to most of the logical operators; NOT, OR, XOR, etc.
0 Kudos
Message 6 of 7
(3,869 Views)
Thanks very much, that works perfectly.

Sarah
0 Kudos
Message 7 of 7
(3,862 Views)