How to convert decimal to binary form along with fractional values?

11 ビュー (過去 30 日間)
rajesh kumar
rajesh kumar 2020 年 3 月 16 日
回答済み: Walter Roberson 2020 年 3 月 16 日
how convert decimal to binary form if the decimal number having fractional values, generally for decimal number 159 i use matlab code de2bi(159,10), if the same number having 159.0178 then how to convert binary form.

採用された回答

Sriram Tadavarty
Sriram Tadavarty 2020 年 3 月 16 日
Hi Rajesh,
A similar question is asked and answered in this
Hope this helps.
Regards,
Sriram

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2020 年 3 月 16 日
While the number is greater than or equal to 1, divide the number by 2 and increment a counter.
While the number is greater than 0:
If the number is greater than or equal to 1 then subtract 1 from the number and emit 1; otherwise emit 0
Multiply the number by 2. Increment the counter.
continue loop
At some point the counter will be 0. Emit '.' at appropriate time.
The above is not tested and probably has some boundary conditions about what to initialize the counter to, and the best time to emit the '.'

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by