From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Binary to integer array trouble

Solved!
Go to solution

So I am trying to read a .dat file and output an array of 4byte (32-bit) integers.

 

My current attempt is to use the Read from binary file. From here I use a StringSubset.vi to remove the first 834 bits as this is non-important information. From here I want to assemble the following string of binary into 4-byte integer values. I am unclear with what sub vi to use after removing the non-important information to convert packets of 4 bytes to numbers.

 

Any help would be super appreciated.

0 Kudos
Message 1 of 11
(3,205 Views)

If you have an array of U8, you can type cast into an array of U32. This will naturally use 4 elements of the input array to create 1 element in the output array, with the most significant byte being the one with the lowest array index.

Capture.PNG

0 Kudos
Message 2 of 11
(3,187 Views)

*.dat is a generic extension and does not tell us anything about the data structure.

Do you have a typical datafile with known data? Please attach it.

 

After trimming 834 bytes, you might try to "unflatten from string" with a 1D I32 or U32 array as type.

 

Do you know the byte order? Try big endian and little endian to see which produces a more reasonable output. 

0 Kudos
Message 3 of 11
(3,181 Views)

Binary to integer.PNG

This would swap the byte order.

0 Kudos
Message 4 of 11
(3,125 Views)
Solution
Accepted by topic author Jewsus

The original VI generates a string, so unflatten as suggested seems like a better choice. Easy to change byte order for testing. 😄

 

read4byteArray.png

Message 5 of 11
(3,117 Views)
0 Kudos
Message 6 of 11
(3,111 Views)

It might be easier to split the read in several operations. Either first read a chunk of 834 bytes and process it as header or throw it away or just set the File Offset to 834 bytes from the start. Then read the remaining data with Binary Read and the correct data type.

Rolf Kalbermatter
My Blog
0 Kudos
Message 7 of 11
(3,102 Views)
Solution
Accepted by topic author Jewsus

My initial thoughts match what rolfk stated.  Just have the Read Binary File do all of the conversion for you.  Just wire an I32 constant to the data type input (on the top of the Read Binary File).  You can also supply the byte order just in case the file is using little endian (big endian is the default).


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
Message 8 of 11
(3,064 Views)

Thanks so much alten, that worked out nicely. I can't believe how much trouble I was having with something so simple lol. Have a great day

 

 

0 Kudos
Message 9 of 11
(3,046 Views)

@Jewsus wrote:

Thanks so much alten, that worked out nicely. I can't believe how much trouble I was having with something so simple lol. Have a great day


Who is alten (altenbach I presume)?  You selected crossrulz' solution.

0 Kudos
Message 10 of 11
(3,036 Views)