How can I cast 4 octets in 32bit signed integer type ?

Hi,
How can I cast a suite of 4 octet/char to obtain an 32 bit signed integer (sint32).
For instance [198 90 72 0] => -967161856 (and not +3327805439).
An equivalent operator to "y = &(type *)&x" in C or to "cast" in LabVIEW.
Thanks,
Benjamin

답변 (2개)

Iain
Iain 2014년 10월 2일
편집: Iain 2014년 10월 2일

0 개 추천

typecast(uint8([1 2 3 4]),'int32')
Benjamin
Benjamin 2014년 10월 2일
Thanks for your answer, it works but before it needs to swap the octets :
data = [198 90 72 0];
signed_integer_32 = typecast(uint8(data(end:-1:1)),'int32')
Benjamin

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

질문:

2014년 10월 2일

답변:

2014년 10월 2일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by