LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

4 byte array to int32

Solved!
Go to solution

Hi All,

 

This should be a nice easy one..

 

Ive got an array of 4 bytes which i want to covert to an unsigned 32bit integer. What the best way of doing this ?

 

Thanks,

 

Richard.

0 Kudos
Message 1 of 19
(11,751 Views)

Hi Richard,

 

The byte array to string function would give you a string output, you can then convert this to whatever you want using the string/number conversion functions

 

I hope this helps!

 

-Michael

 

0 Kudos
Message 2 of 19
(11,746 Views)

Hi Richard,

 

more options:

- use the JoinNumbers function to join your bytes as needed

- use TypeCast to cast your array into an I32 number

- Use UnflattenFromString after converting the U8 array to a string

 

Please provide an example with an U8 array and expected output value…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 3 of 19
(11,735 Views)

I have an Input byte array of

 

0

0

214

72

 

and i need to made this into an int 32. The value represents mCelsius. so i would expect to see around 20000-50000 (20-50 celsius).

0 Kudos
Message 4 of 19
(11,722 Views)

Try the type case Gerd mentioned.

 

Worst coes to worst you will have to re-arange the bytes to account ofr little endian etc.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 5 of 19
(11,716 Views)
Solution
Accepted by topic author lvrichard

Hi Richard,

 

several options:

check.png

All of them give "54856" (=214*256+72) as result…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 6 of 19
(11,711 Views)

Hi Richard,

 

one more option:

check.png

(You might use one of the other options instead… :))

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 7 of 19
(11,704 Views)

Hi GerdW

 

Thanks very much for going out your way to do this!

 

Just what i wanted !!

 

Thanks again,

 

Richard.

0 Kudos
Message 8 of 19
(11,700 Views)

Just something to keep in mind: Endianess has often bitten me in the butt.  LabVIEW currently uses Big Endian for all of its data storage, so the Type Cast will work.  But I prefer to use the Unflatten From String approach just in case I find that the data string I am recieving is actually Little Endian (there is an input for the Unflatten From String for Endianess).


GCentral
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 9 of 19
(11,673 Views)

Hi Crossrulz,

 

Ive noticed i'm not getting consistent results from the type cast function, which is annoying!! However, the self indexing for loop Gerd posted seems to be the most reliable method. Is there any drawbacks to using the method? Is it more intensive etc??

 

Thanks,


Richard.

0 Kudos
Message 10 of 19
(11,634 Views)