How to display double-precision floating-point number in binary representation?

Hello, I'm currently working with Simulink. There I'm reading a value out of a Data Store Memory. This value is a double value, so a floating-point number. Now I want to display this number in its binary representation. Since this is not possible with a display block, I'm looking for another way. Thanks!

 採用された回答

Walter Roberson
Walter Roberson 2018 年 6 月 25 日
MATLAB Function block. You can typecast() to uint64, and then you can use bitget() . Or you can use num2hex() on the floating point and then decode the hex if you want a binary representation.
If you do use num2hex, be aware that the output is in Big Endian order -- most significant bit left to least significant right. On all Intel x86 and x64 architectures, the order in memory is Little Endian.
>> dec2hex(typecast(hex2num('0123456789ABCDEF'),'uint8'))
ans =
8×2 char array
'EF'
'CD'
'AB'
'89'
'67'
'45'
'23'
'01'

1 件のコメント

Tim Leschinsky
Tim Leschinsky 2018 年 6 月 25 日
Thanks for your answer, I use Big Endian anyway, so it's just fine.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

製品

リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by