Binary String to double?

15 ビュー (過去 30 日間)
Cory Zuber
Cory Zuber 2018 年 4 月 12 日
編集済み: Walter Roberson 2018 年 4 月 12 日
Here is a piece of code where I take a double and convert it to a binary string.
S=[1.123,2,3];
q = quantizer('double');
B = num2bin(q,S(1));
Which returns
B = '0011111111110001111101111100111011011001000101101000011100101011'
In my code, I randomly change one bit, but I need a way to convert it back to a double.
  1 件のコメント
KSSV
KSSV 2018 年 4 月 12 日
bin2dec

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

回答 (1 件)

Walter Roberson
Walter Roberson 2018 年 4 月 12 日
編集済み: Walter Roberson 2018 年 4 月 12 日
bin2num(q, B)
Note:
If you randomly change the first bit then you will get the negative of the original value. If you randomly change one of the 11 bits after that, then you will affect the entire scale of the number, equivalent to multiplying or dividing by a power of 2.
If the number happened to quantize to 0, then if you change one of the last 52 bits then you would have a "denormalized number", which would be a value between 4.94065645841247e-324 and 2.2250738585072e-308

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by