LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

4 byte array to int32

Solved!
Go to solution

Hi Richard,

 

drawbacks: it's the solution requiring the most computational power.

But then any modern computer is able to calc this FOR loop with 4 iterations within nanoseconds…

 

Why don't you use solution 4 ("I32_4")? It basically does the same with less (polymorph) operations…

Best regards,
GerdW


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

@lvrichard wrote:

Ive noticed i'm not getting consistent results from the type cast function, which is annoying!!.


That makes me think there is something wrong with your original data array.  Maybe you are getting too many or not enough bytes sometimes.  Why is the data coming from?


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 12 of 19
(3,016 Views)

@lvrichard wrote:

 

Ive noticed i'm not getting consistent results from the type cast function, which is annoying!!


Please define the word "inconsistent". Is it sometimes wrongalmost right, or always wrong? My best guess is that your input data array is not U8, but some other integer type. It could also be a byte order thing as Ben already mentioned.

Can you attach a simple VI containing your data that generates incrrect result as a diagram constant?

0 Kudos
Message 13 of 19
(2,974 Views)

Hi

Thanks for posting the solution to this query. However, I just wanted to know how to convert a byte array, having more than 4 bytes into integer. This solution works only for 4-byte array.
Shall be highly grateful for your response. Thanks

0 Kudos
Message 14 of 19
(2,366 Views)

Hi sakshirawal,

 

how to convert a byte array, having more than 4 bytes into integer.

Using I64/U64 datatypes you can create integers consisting of 8 bytes.

Does that help you?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 15 of 19
(2,363 Views)

@sakshirawal wrote:

Hi

Thanks for posting the solution to this query. However, I just wanted to know how to convert a byte array, having more than 4 bytes into integer. This solution works only for 4-byte array.
Shall be highly grateful for your response. Thanks


What do the other bytes in the array besides the four represent?  You can just discard them and only use the 4 you using either Array Subset or Delete from Array.

0 Kudos
Message 16 of 19
(2,355 Views)

@sakshirawal wrote:

Thanks for posting the solution to this query. However, I just wanted to know how to convert a byte array, having more than 4 bytes into integer. This solution works only for 4-byte array.


You added to an old thread with a very vague question that cannot be given a very specific answer.

 

  • How many bytes are in the array?
  • What is the representation of the desired integer? (scalar U64, I32 array? etc.)

In general, the provided solution works for anything where the input and output have matching amounts of bytes overall. You might also need to worry about byte order.

 

Easiest would be if you attach a simplified version of your code showing us what you have and what you want to get out of it.

 

0 Kudos
Message 17 of 19
(2,343 Views)

@crossrulz wrote:

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


I've actually had it where the incoming data had a different endianness depending on the source.  Same data format, different endianness.  Thank you, Unflatten from String, for allowing me to choose the endianness based on the source!

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 18 of 19
(2,327 Views)

@lvrichard wrote:

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.


If you can't fill up the data type with data, you're going to get weird results, because the missing byte(s) will shift the data one way or the other.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 19 of 19
(2,327 Views)