필터 지우기
필터 지우기

How do i convert a Base-2 number into Base-10?

조회 수: 9 (최근 30일)
Bella
Bella 2016년 5월 22일
편집: dpb 2016년 5월 23일
If the number is 1011001 then I thought I would do 2^0+2^3+2^4+2^6= 89 then (8x10^1)+(9x10^0)= 89
Would 89 be correct or should it be -89 because it starts with a 1? or is that only for integer representation?
  댓글 수: 2
Stephen23
Stephen23 2016년 5월 22일
The answer depends entirely on the number encoding scheme that you are talking about. If you only consider the binary digits as being digits of a simple integer then the decimal equivalent is 89. However if you are talking about any possible binary encoding scheme, such as those commonly used to encode signed integers or floating point values then you first have to define the encoding before you can get an answer.
dpb
dpb 2016년 5월 23일
편집: dpb 2016년 5월 23일
In this day and age it would be unusual for the actual representation to have only 7 bits so one would presume the sign is resolved as the value is actually '0101 1001'.
That is absolutely so can't be proven from the data given, granted, but that's what my crystal ball says... :)

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

답변 (1개)

Todd Leonhardt
Todd Leonhardt 2016년 5월 23일
You can use bin2dec() to convert a binary number string to a decimal number like so:
x = bin2dec('0111');
In this case x == 7. bin2dec assumes you are dealing with non-negative integers.
If you have either the Communications Toolbox (bi2de) or Fixed-Point Designer Toolbox (bin), then there are some other options available to you as well.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by