04-19-2010 01:22 AM
A variable will be passed to me by I32 in 4 bytes.
But this 4 bytes is inside a long array in format of U8.
May I know how to do the data convert, thanks.
04-19-2010 01:34 AM
How long is the array? Do you need to (A) make a 4 times shorter I32 array or (B) do you only need to convert 4 bytes?
Anyway, for (A) use array subset to get the desired 4 bytes and typecast it to I32 (assuming the byte order is big endian). For (B) you would typecast the entire array to a I32 array.
(If your original data is little endian, you need to swap the bytes, for example by converting the U8 array to a string, then unflatten to I32 using little endian byte order.)
04-19-2010 01:52 AM
The U8 array is A.
In side A, A(4) to A(7) need to convert to a I32. May I know how to do a typecast.
It need to handle realtime cycle calling, so may need high efficience.
04-19-2010 02:15 AM
Hi alex,
use the Typecast function, wire the 4-byte array to the x input and a I32 constant to the type input...
04-19-2010 02:23 AM - edited 04-19-2010 02:26 AM
Try this, should be pretty efficient. (For little endian, reverse the array subset before typecasting).
04-19-2010 10:27 AM - edited 04-19-2010 10:28 AM
altenbach wrote:Note that the diagram constant is I32, the value does not matter, just the type)
02-22-2011 10:07 AM
I get an error when using this. I have an integer stored in a 4-byte array, and use type-cast to retrieve it. Problem is, the integer comes out wrong in the indicator. The byte order is big endian and after type casting I have a big endian integer. But the indicator seems to expect a little endian integer. Reversing the byte array still produces a big endian integer. I have to do this:
Then I get the correct result.
02-22-2011 10:39 AM - edited 02-22-2011 10:43 AM
Numerics in LabVIEW are internally always big endian.
Your code is way too complicated. Why use "split array" to take a subarray?
Have you tried unflatten from string instead? One step (!) and you can define the byte order.
Please attach a small VI containing a typical binary string as a diagram constant and tell us what the result should be.
02-22-2011 11:42 AM
Sorry, it seems my data was malformed when being sent to the VI. "split array" was there for a different task.
Please forget my post. I'm sorry for wasting your time.
01-19-2014 02:19 AM
Thank you Dr. Altenbach!
I can't mark your answer as a solution, as I am not the original poster.
However, I had this problem (I have an array of 8-bit unsigned integers where each four of them makes up one (little endian) 32-bit integer, and I need to convert to an array of 32 bit numbers.
Your solution (with the reverse array on the subset) worked beautifully for me (and as a bonus I am now familiar with some LabVIEW functions that I was unaware of previously).
Thank you.
Batya