LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Convert U8 array to 16bit hex num

Hi,
I have an array of U8. I want to pull the first two 8 bit elements and join them to produce a 16 bit hex number.
Ex:
If Array ---> FE 0C 12 D4.......
Here;
Element1---> FE
Element2---> 0C
Then;
16 bit hex--> FE0C

I tried doing this, but could not come with a way of joining two 8 bit data into a 16 bit data.
Please let me know how this can be done.
A small example program would be helpful.
Thanks.
0 Kudos
Message 1 of 7
(7,632 Views)
Use the decimate array vi (array pallet) to split the U8 array into two arrays, high byte and low byte. Index each array. Convert the high byte to U16. Multiply the high byte by 256 (100h) and add the low byte. Do this for each element of the arrays.

Dave.
==============================================

Message 2 of 7
(7,632 Views)
Typecasting will do it too.
=====================================================
Fading out. " ... J. Arthur Rank on gong."
Message 3 of 7
(7,632 Views)
Attahced VI shows an easy way to do this.
- tbob

Inventor of the WORM Global
Message 4 of 7
(7,632 Views)
Shreesha wrote in news:50650000000800000036EA0000-
1079395200000@exchange.ni.com:

> Hi,
> I have an array of U8. I want to pull the first two 8 bit elements
> and join them to produce a 16 bit hex number.
> Ex:
> If Array ---> FE 0C 12 D4.......
> Here;
> Element1---> FE
> Element2---> 0C
> Then;
> 16 bit hex--> FE0C
>
> I tried doing this, but could not come with a way of joining two 8
> bit data into a 16 bit data.
> Please let me know how this can be done.
> A small example program would be helpful.
> Thanks.

Use the "Type Cast" function
(Function palette->Advanced->Data Manipulation->Type cast)

Wire your U8 array to the x terminal.
Wire an empty U16 (or I16) array to the typeterminal.

The output should now be a 16 bit
array.

I think this should work an all platforms (both high endian and low endian
systems).

--
Rolf
0 Kudos
Message 5 of 7
(7,632 Views)
Dave Kaufman wrote in news:50650000000500000098B30100-
1079395200000@exchange.ni.com:

> Use the decimate array vi (array pallet) to split the U8 array into
> two arrays, high byte and low byte. Index each array. Convert the
> high byte to U16. Multiply the high byte by 256 (100h) and add the
> low byte. Do this for each element of the arrays.

Do the split as describe above. Then multiply the high byte array by 256
(100h) and add the low byte array.

You don't need to iterate over all elements in the array.

--
Rolf
0 Kudos
Message 6 of 7
(7,632 Views)
Rolf Østvik wrote:

> Use the "Type Cast" function
> (Function palette->Advanced->Data Manipulation->Type cast)
>
> Wire your U8 array to the x terminal.
> Wire an empty U16 (or I16) array to the typeterminal.
>
> The output should now be a 16 bit array.
>
> I think this should work an all platforms (both high endian and low endian
> systems).

Yes exactly, because the desired transformation is that of a Big Endian
(network byte order or MSB first) and that is what LabVIEW always
assumes when typecasting or flattening independant of the underlying CPU.

Rolf Kalbermatter
Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
Message 7 of 7
(7,632 Views)