LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Data covert: 1byte integer to 4 byte integer

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.

0 Kudos
Message 1 of 10
(4,187 Views)

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.)

 

 

Message 2 of 10
(4,186 Views)

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.

0 Kudos
Message 3 of 10
(4,172 Views)

Hi alex,

 

use the Typecast function, wire the 4-byte array to the x input and a I32 constant to the type input...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 4 of 10
(4,164 Views)

Try this, should be pretty efficient. (For little endian, reverse the array subset before typecasting).

 

 

(Array subsettypecast. Note that the diagram constant is I32, the value does not matter, just the type)
 
Message Edited by altenbach on 04-19-2010 12:26 AM
Message 5 of 10
(4,159 Views)

altenbach wrote:

Note that the diagram constant is I32, the value does not matter, just the type)


 

 Just to make things more clear. The value of the diagram constant matters for "array subset". It does not matter for typecast.
 
Message Edited by altenbach on 04-19-2010 08:28 AM
Message 6 of 10
(4,113 Views)

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:

 

wrap.png

 

Then I get the correct result.

 

 

Lars Melander
Uppsala Database Laboratory, Uppsala University
0 Kudos
Message 7 of 10
(3,796 Views)

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.

0 Kudos
Message 8 of 10
(3,784 Views)

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.

Lars Melander
Uppsala Database Laboratory, Uppsala University
0 Kudos
Message 9 of 10
(3,770 Views)

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

0 Kudos
Message 10 of 10
(3,360 Views)