Converting decimal value to binary
2 次查看(过去 30 天)
显示 更早的评论
I have to convert decimal value to binary ,in hich my decimal value is in negative and positive
my values are
a=[ 0.0803
0.0726
0.0469
-0.0038
-0.0421]
please help how to convert to binary
0 个评论
采纳的回答
Harshit
2012-11-21
http://www.mathworks.in/help/matlab/ref/dec2bin.html. See this. It will do 2's complement for negative numbers
3 个评论
Harshit
2012-11-21
ok sorry. i didn't notice. for negative integers a
if true
% a=-x;
b=dec2bin(2^n+a);
end
for fractions convert first them into positive say -16.56 = -17 + 0.42. Get the binary of negative using the scheme above and get the binary of 0.42 bu multiplying by 2 at each instant and gathering the integer part. You will do it ofcourse on the basis of precision you required. n denotes the number of integer bit for you.
更多回答(1 个)
Walter Roberson
2012-11-21
There are three competing standards for the representation of negative integers.
There are many methods for the representation of fractions. The ones used to represent floating point double precision numbers use some schemes that required work to deal with unusual cases.
We cannot tell you how to do the conversion until you tell us which representation you wish to use.
4 个评论
Walter Roberson
2012-11-21
Use the following standard but delete the last two bits of the mantissa:
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!