views:

196

answers:

4

Or, what is the range of numbers that can be represented on a 4-bit machine using 2s-complement?

+1  A: 

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

This should be straightforward to work out yourself.

Anon.
+2  A: 

That would be -8 to +7

JustJeff
Thank you, I had a brain-fart and was deciding if -9 would work.
Matt
Assuming 2's complement.
Craig McQueen
@C.McQueen - he *said* 2's complement, so yeah, I assumed that.
JustJeff
Very sorry, my mistake, he did say that too.
Craig McQueen
+4  A: 

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

Bill the Lizard
A: 

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

Jeff