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

32 ビュー (過去 30 日間)
Bella 2016 年 5 月 22 日

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 件のコメント表示非表示 1 件の古いコメント
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 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.

サインインしてコメントする。

### Community Treasure Hunt

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

Start Hunting!