Effacer les filtres
Effacer les filtres

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

2 vues (au cours des 30 derniers jours)
Benjamin
Benjamin le 2 Oct 2014
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

Réponses (2)

Iain
Iain le 2 Oct 2014
Modifié(e) : Iain le 2 Oct 2014
typecast(uint8([1 2 3 4]),'int32')

Benjamin
Benjamin le 2 Oct 2014
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

Community Treasure Hunt

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

Start Hunting!

Translated by