covert 9.2532 decimal into binary
古いコメントを表示
convert decimal into binary with decimal point
回答 (1 件)
Roger Stafford
2017 年 3 月 16 日
編集済み: Roger Stafford
2017 年 3 月 16 日
function s = binstr(x)
if ~isfinite(x)|(length(x)~=1), error('x must be a finite scalar.'),end
b = (x<0); x = abs(x);
s = zeros(1,53);
[f,e] = log2(x);
for i = 1:53
f = 2*f;
d = floor(f);
f = f - d;
s(i) = d+48;
end
s = ['0.' s sprintf('*2^(%d)',e)];
if b, s = ['-' s]; end
s = char(s);
return
9 件のコメント
Pratik Anandpara
2017 年 3 月 16 日
Pratik Anandpara
2017 年 3 月 16 日
Roger Stafford
2017 年 3 月 16 日
binstr(9.2532)
Pratik Anandpara
2017 年 3 月 16 日
Pratik Anandpara
2017 年 3 月 16 日
Roger Stafford
2017 年 3 月 16 日
編集済み: Roger Stafford
2017 年 3 月 16 日
The function should generate a string which consists of binary digits with a binary point and a power of two. Write
s = binstr(9.2532)
and display the string. The string I get on my ancient computer is:
0.10010100000011010001101101110001011101011000111000100*2^4
Pratik Anandpara
2017 年 3 月 16 日
編集済み: Pratik Anandpara
2017 年 3 月 16 日
Pratik Anandpara
2017 年 3 月 16 日
Roger Stafford
2017 年 3 月 16 日
Change 'finite' to 'isfinite'.
カテゴリ
ヘルプ センター および File Exchange で MATLAB についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!