开发者

What is the "biggest" negative number on a 4-bit machine?

Or, what开发者_开发百科 is the range of numbers that can be represented on a 4-bit machine using 2s-complement?


That would be -8 to +7


The range is -8 to 7, or 1000 to 0111. You can see the full range here.


4 bits (using 2's complement) will give you a range from -8 to 7.

This should be straightforward to work out yourself.


Range in twos complement will be:

-1 * 2 ^ (bits - 1)

to

2 ^ (bits - 1) - 1

So for 4 bits:

-1 * 2 ^ (4 - 1) = -1 * 2 ^ 3 = -8

to

2 ^ (4 - 1) - 1 = 2 ^ 3 - 1 = 7

Also, if you are interested and for others maybe browsing this question - twos complement is used for easy binary arithmetic:

to add - you just add the two numbers without conversion and disregard the overflow:

-6 + 7 = 1 is

1010 = -6
0111 = 7
------
(1)0001 = 1 (ignoring the overflow)

...and more yet - to convert a negative binary number to its opposite positive number:

if the sign bit (highest order bit) is 1, indicating negative... reading from least significant to most significant bit (right to left), preserve every bit up through the first "1", then invert every bit after that.

So, with 8 bit
10011000 .. becomes
01101000 (* -1) = 104 * -1 = -104

and that is why 10000000 is your lowest negative number (or in X bit 1000.all zeroes..000), it translates to unsigned 10000000 * -1 = -128

Maybe a long winded answer but to those without the 1s and 0s background I figure it is useful


Well let's dissect this question.

Firstly, the question should be framed as - "The least*(because it is negative, so biggest is not the right usage)* possible negative number to be stored in 4-bit would be?"

Numbers are of two types - Signed (holds both + and - numbers ) Unsigned (holds only + numbers)

We will be using binary representation to understand this.

For Unsigned - 4-bit minimum number = 0000 (0) 4-bit maximum number = 1111 (255) So range would be Range : 0-15

For Signed 4-bits, first bit represent sign(+/-) and rest 3-bits represent number.

4-bit minimum will be a negative number. So replace the first bit(MSB) with 1 in 0000(least unsigned number), making it 1000.

Calculate decimal equivalent of 1000 = 1*2^3 = 8 So, number would be -8 (- as we have 1 as the first bit in 1000)

4-bit maximum will be a positive number. So replace the first bit(MSB) with 0 in 1111(largest unsigned number), making it 0111.

Calculate decimal equivalent of 0111 = 1*2^2 + 1*2^1 + 1*2^0 = 7 So, number would be +7 (+ as we have 0 as the first bit in 0111)

Range would be -8 to +7.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜