binary to decimal when binary with radix point
조회 수: 3 (최근 30일)
이전 댓글 표시
I have to convert the following binary number to decimal: 11000101.101
I am using
bin2dec('binary number')
but is does not work with a radix point
댓글 수: 0
답변 (2개)
Walter Roberson
2016년 12월 30일
parts = strsplit(str, '.') ;
dec2bin(parts{1}) + dec2bin(parts{2})/2^length(parts{2})
댓글 수: 3
Stephen23
2016년 12월 30일
@Harel Harel Shattenstein: there is a mistake in this untested code, the function dec2bin should actually be bin2dec. Otherwise it is correct.
Walter Roberson
2016년 12월 30일
parts = strsplit(str, '.') ;
bin2dec(parts{1}) + bin2dec(parts{2})/2^length(parts{2})
That's what I get for posting at 3 in the morning ;-)
참고 항목
카테고리
Help Center 및 File Exchange에서 Database Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!