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

21 次查看(过去 30 天)
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?

采纳的回答

James Tursa
James Tursa 2019-7-24
编辑:James Tursa 2019-7-24
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 个评论
Walter Roberson
Walter Roberson 2021-8-9
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.

请先登录,再进行评论。

更多回答(1 个)

Walter Roberson
Walter Roberson 2019-7-24
num2hex() gives a single call for this.

类别

Help CenterFile Exchange 中查找有关 Programmatic Model Editing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by