covert 9.2532 decimal into binary

1 次查看(过去 30 天)
convert decimal into binary with decimal point

回答(1 个)

Roger Stafford
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
Pratik Anandpara 2017-3-16
s=binstr(9.2532) i edit this in command window or function file

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 String Parsing 的更多信息

标签

尚未输入任何标签。

产品

Community Treasure Hunt

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

Start Hunting!

Translated by