Converting decimal value to binary

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

 채택된 답변

Harshit
Harshit 2012년 11월 21일

0 개 추천

http://www.mathworks.in/help/matlab/ref/dec2bin.html. See this. It will do 2's complement for negative numbers

댓글 수: 3

Pat
Pat 2012년 11월 21일
But that pages says d must be a nonnegative integer smaller than 2^52.
another thing do you have and idea how to convert the above values into 14 bit
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.
Pat
Pat 2012년 11월 21일
ok harshit thanks can you please tell how to convert values in a to signed 14 bit,those are ouputs of wavelet coefficients of a soundwave

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2012년 11월 21일

0 개 추천

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

Pat
Pat 2012년 11월 21일
Walter can you please tell what is
which representation you wish to use.
Walter Roberson
Walter Roberson 2012년 11월 21일
Is the representation one's complement, two's complement, or separate-sign? How many bits of exponent? How many bits of mantissa? Is the exponent separate-sign or two's complement or biased? What is the power that the exponent is to be raised to? Is the first bit of the mantissa to be explicit, or is it to be "hidden"?
For example, show us the exact bit breakdown you wish to use for -1E+42
Pat
Pat 2012년 11월 21일
Walter any of the one which will be useful for sampling the signal into 14 bits

댓글을 달려면 로그인하십시오.

태그

질문:

Pat
2012년 11월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by