DECIMAL To Binary Representation

1 回表示 (過去 30 日間)
Dereje
Dereje 2018 年 1 月 28 日
コメント済み: John D'Errico 2018 年 1 月 28 日
Need help for a code that changes numbers into binary normal representation and storage in a single precision. Not MATLAB built-in converter. Thanks
  10 件のコメント
Dereje
Dereje 2018 年 1 月 28 日
Of course if it is -ve integer, then the code considers it as a +ve integer but for me I know that my input is -ve and I considers it as -ve. For example if my input is
24
Then the out put is
'11000'
In the same way for -24 is also
'11000'
Since the input is -ve value it is clear that you must add -ve to get the correct result. I haven't got a result for fractions.
John D'Errico
John D'Errico 2018 年 1 月 28 日
I suppose I need to post num2bin sometime. Too many round-tuits.

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

回答 (1 件)

Stephen23
Stephen23 2018 年 1 月 28 日
編集済み: Stephen23 2018 年 1 月 28 日
Where N is an integer:
>> N = -24;
>> V = pow2(1+fix(log2(abs(N))):-1:0);
>> Z = fix(mod(abs(N),V(1:end-1))./V(2:end)) % numeric vector
Z =
1 1 0 0 0
>> char(Z+'0') % char vector
ans = 11000

カテゴリ

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