필터 지우기
필터 지우기

Real value to binary

조회 수: 13 (최근 30일)
b
b 2012년 5월 11일
How can i convert my real value to binary digits?
For example; i have values within [0,25] range and 15 binary digits to represent a variable.(4 variables totally)
How can i do that and also reverse of that?
  댓글 수: 3
b
b 2012년 5월 11일
it will be 3 places after the decimal point.
so i think that i will have 10^3*25 equal size.
that is equal to
2^14 < 25000 < 2^15. so i will have 15 bits. ??
Walter Roberson
Walter Roberson 2012년 5월 11일
3 decimal places requires 10 bits to resolve (2^(-10) = 1/1024)
You get slightly better resolution if you use 2^10 than if you use 10^3. It depends though on whether resolution is your goal or if "3 decimal places" is your goal.

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

채택된 답변

Sean de Wolski
Sean de Wolski 2012년 5월 11일

추가 답변 (3개)

Honglei Chen
Honglei Chen 2012년 5월 11일
Are you asking things like dec2bin and bin2dec?
x = 20;
dec2bin(20,15)

Walter Roberson
Walter Roberson 2012년 5월 11일
dec2bin(round(Values * 2^10), 15) - '0'
  댓글 수: 5
b
b 2012년 5월 11일
Sorry for that but i want to ask another thing..
my range is between 0 and 25.
when i put e.g. 2.5 to this formula,this gives me wrong result
Walter Roberson
Walter Roberson 2012년 5월 11일
If you go up to 25 then you need the 2^10 not 2^11

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


b
b 2012년 5월 11일
Actually, if i put 2.154 as a real value within [0,25]
it should not give me 000000000000010. it represents for my range 0.001 something like that.

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by