취소
다음에 대한 결과 표시 
다음에 대한 검색 
다음을 의미합니까? 

4 byte array to int32

해결 완료!
솔루션으로 이동

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.

0 포인트
1/19 메시지
15,779 조회수

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

 

0 포인트
2/19 메시지
15,774 조회수

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…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
3/19 메시지
15,763 조회수

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

0 포인트
4/19 메시지
15,750 조회수

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

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 포인트
5/19 메시지
15,744 조회수
솔루션
주제 작성자 lvrichard이(가) 승인함

Hi Richard,

 

several options:

check.png

All of them give "54856" (=214*256+72) as result…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
6/19 메시지
15,739 조회수

Hi Richard,

 

one more option:

check.png

(You might use one of the other options instead… :))

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
7/19 메시지
15,732 조회수

Hi GerdW

 

Thanks very much for going out your way to do this!

 

Just what i wanted !!

 

Thanks again,

 

Richard.

0 포인트
8/19 메시지
15,728 조회수

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



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 포인트
9/19 메시지
15,701 조회수

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.

0 포인트
10/19 메시지
15,662 조회수