Hi, I want to convert decimals between 0 and 1 into binary form which can be represented exactly up to 11 binary digits say, so 1/2^11, 2/2^11, 3/2^11......to 2^11-1/2^11 only, is there a good code or build in function for this?
Also, is there a function which can return the no of 1's or 0's in the binary form of a particular value above?
Thanks
Joe

 채택된 답변

Walter Roberson
Walter Roberson 2014년 1월 20일

1 개 추천

B = dec2bin( round(X * 2^11), 11 ) - '0';
nnz(B)
sum(B)
length(B) - nnz(B)

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Data Type Conversion에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

질문:

Joe
2014년 1월 20일

댓글:

Joe
2014년 1월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by