MATLAB Answers

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

10 views (last 30 days)
glentall
glentall on 24 Jul 2019
Commented: glentall on 29 Jul 2019
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?

  0 Comments

Sign in to comment.

Accepted Answer

James Tursa
James Tursa on 24 Jul 2019
Edited: James Tursa on 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.

  2 Comments

glentall
glentall on 29 Jul 2019
I first tried your equations using the default variable type (double) at the Matlab command window and had erroneous results. Once I remembered to change 's' to a 'single,' I got the correct results that I desired.
Thanks James!

Sign in to comment.