dec2bin function provides wrong answer
조회 수: 10 (최근 30일)
이전 댓글 표시
For example, when I type dec2bin(8), I expect the answer is 100b, instead the returned value in command window is actually 1000
댓글 수: 2
채택된 답변
John D'Errico
2022년 10월 27일
편집: John D'Errico
2022년 10월 27일
So the binary representation of 8 is not 1000?
Let me see, 8 = 1*2^3 + 0*2^2 + 0*2^1 + 0*2^0.
I think you are mistaken.
dec2bin(8)
1*2^3 + 0*2^2 + 0*2^1 + 0*2^0
In fact, the number 100 in binary is the decimal 4.
1*2^2 + 0*2^1 + 0*2^0
Maybe you forgot about that least order (units) bit. Note that if binary numbers did not have that least order unit bit, then a binary number could never represent any odd number. And that in itself would be quite an "odd" thing.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!