08-15-2016 09:25 AM
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.
Solved! Go to Solution.
08-15-2016 09:30 AM - edited 08-15-2016 09:32 AM
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
08-15-2016 09:41 AM - edited 08-15-2016 09:42 AM
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…
08-15-2016 09:47 AM
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).
08-15-2016 09:52 AM
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
08-15-2016 10:06 AM - edited 08-15-2016 10:07 AM
08-15-2016 10:11 AM
08-15-2016 10:14 AM
Hi GerdW
Thanks very much for going out your way to do this!
Just what i wanted !!
Thanks again,
Richard.
08-15-2016 12:00 PM
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).
08-16-2016 02:48 AM
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.