Matlab 十进制整数转化为二进制原码、补码
程序员文章站
2022-07-15 10:25:22
...
整数转化为二进制原码
function y = dec2yuanma(x,N)
%1<=N<=53
y=zeros(N,length(x));
for i=1:length(x)
if x(i)<0
x(i)=2.^(N-1)-x(i);
end
d=flip(dec2bin(x(i)));
b=zeros(N,1);
for j=1:length(d)
b(j)=str2num(d(j));
end
y(:,i)=b;
end
end
整数转化为二进制补码
function y = dec2buma(x,N)
%1<=N<=53
y=zeros(N,length(x));
for i=1:length(x)
if x(i)<0
x(i)=2.^N+x(i);
end
d=flip(dec2bin(x(i)));
b=zeros(N,1);
for j=1:length(d)
b(j)=str2num(d(j));
end
y(:,i)=b;
end
end
上一篇: 理解JVM
下一篇: WEB开发中如何将日志设置到当前应用下面