no of bits increases after decimal to binary conversion

1 回表示 (過去 30 日間)
Pat
Pat 2012 年 11 月 26 日
I performed
a =
5
-5
b=dec2bin(2^4+a)
b =
10101
01011
I have given 4 bits but why my output gives 5 bit value,also for 5 why may MSB is 1`,for -5 why it is 0,also if i perform
a=0;
b=dec2bin(2^4+a)
b =
10000
In this why my MSB is 1

回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2012 年 11 月 26 日
編集済み: Azzi Abdelmalek 2012 年 11 月 26 日
2^4+5 requires at least 5 bits
If you want to represent a with 4 bits
b=dec2bin(a,4)
also, to use dec2bin(a), a must be non negative integer
  3 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2012 年 11 月 26 日
Yes, That what I said above, to represent signed binary number use 2's complement representation http://en.wikipedia.org/wiki/Two%27s_complement
Pat
Pat 2012 年 11 月 26 日
Azzi can u please provide me an example ,i understood concept ,but dont know how to start with

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

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by