Binary floating point Representation in Matlab

조회 수: 32 (최근 30일)
Johan Johan
Johan Johan 2019년 9월 12일
편집: James Tursa 2022년 9월 22일
Floating-point numbers are represented as
X=(-1)^s*m*2^c.
s: the sign
m:matissa
c:exponent
For example
The value 1.9844 as Binary floating point would be REF
0 01111111 11111100000000011010010
^ Sign bit
^^^^^^^^ Exponent
^^^^^^^^^^^^^^^^^^^^^^^ Fraction
But in matlab ,how doing the same work in this vector ?
A=[ 0.1900 -0.0300 -0.1300 0 0.1500 -0.0700 0.0500 0.1600 -0.2500 -0.1900];

채택된 답변

James Tursa
James Tursa 2019년 9월 12일
Did you try it?
>> A=[ 0.1900 -0.0300 -0.1300 0 0.1500 -0.0700 0.0500 0.1600 -0.2500 -0.1900];
>> dec2bin(typecast(A,'uint64'),64)
ans =
0011111111001000010100011110101110000101000111101011100000000000
1011111110011110101110000101000111101011100001010010000000000000
1011111111000000101000111101011100001010001111010111000000000000
0000000000000000000000000000000000000000000000000000000000000000
0011111111000011001100110011001100110011001100110011010000000000
1011111110110001111010111000010100011110101110000101000000000000
0011111110101001100110011001100110011001100110011001101000000000
0011111111000100011110101110000101000111101011100001010000000000
1011111111010000000000000000000000000000000000000000000000000000
1011111111001000010100011110101110000101000111101011100000000000
  댓글 수: 4
Nolan Dyck
Nolan Dyck 2022년 9월 22일
@James Tursa dec2bin appears to be working properly in R2022a Update 1, at least for your example.
>> dec2bin(typecast(0.1900, 'uint64'), 64)
ans =
'0011111111001000010100011110101110000101000111101011100001010010'
James Tursa
James Tursa 2022년 9월 22일
편집: James Tursa 2022년 9월 22일
Good to know. Thanks. Online R2022b seems to work as well:
dec2bin(typecast(0.1900, 'uint64'), 64)
ans = '0011111111001000010100011110101110000101000111101011100001010010'

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Bruno Luong
Bruno Luong 2019년 9월 12일
편집: Bruno Luong 2019년 9월 16일
To overcome the limitation of dec2bin at 52 bits
A=[ 0.1900 -0.0300 -0.1300 0 0.1500 -0.0700 0.0500 0.1600 -0.2500 -0.1900]
b = reshape(dec2bin(flipud(reshape(typecast(A,'uint8'),8,[])),8)',64,[])'
ans =
10×64 char array
'0011111111001000010100011110101110000101000111101011100001010010'
'1011111110011110101110000101000111101011100001010001111010111000'
'1011111111000000101000111101011100001010001111010111000010100100'
'0000000000000000000000000000000000000000000000000000000000000000'
'0011111111000011001100110011001100110011001100110011001100110011'
'1011111110110001111010111000010100011110101110000101000111101100'
'0011111110101001100110011001100110011001100110011001100110011010'
'0011111111000100011110101110000101000111101011100001010001111011'
'1011111111010000000000000000000000000000000000000000000000000000'
'1011111111001000010100011110101110000101000111101011100001010010'

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by