How can I show the 4-byte hex representation of a single precison float value?

21 Ansichten (letzte 30 Tage)
Is there a way to show/display the 4-byte hex and/or binary representation of a single precision float value in Matlab and/or Simulink?

Akzeptierte Antwort

James Tursa
James Tursa am 24 Jul. 2019
Bearbeitet: James Tursa am 24 Jul. 2019
s = your single float number
h = dec2hex(typecast(s,'uint32'),8)
And the reverse is
s = typecast(uint32(hex2dec(h)),'single')
If you want binary then see the dec2bin( ) and bin2dec( ) functions.
  4 Kommentare
li li
li li am 9 Aug. 2021
best method of format conversion from hex to float !
very thanks!
Walter Roberson
Walter Roberson am 9 Aug. 2021
s = rand('single')
s = single 0.7387
dec2hex(typecast(s,'uint32'),8)
ans = '3F3D1D5B'
num2hex(s)
ans = '3f3d1d5b'
In my opinion, numhex() is better for this purpose, as it is shorter and does not require as much technical knowledge.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Walter Roberson
Walter Roberson am 24 Jul. 2019
num2hex() gives a single call for this.

Kategorien

Mehr zu Programmatic Model Editing finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by