-1

For an 8-bit cell that uses two's complement binary representation for storing SIGNED integers, what is the range of integers for this cell as written in binary?

I had 00000000 to 11111111 because I thought the decimal range was 0 to -1, but I don't think I'm approaching the problem the right way.

uxnzdwsi
  • 1
  • 1
  • Does this answer your question? [Why is the range of signed byte is from -128 to 127 (2's complement) and not from -127 to 127?](https://stackoverflow.com/questions/11433789/why-is-the-range-of-signed-byte-is-from-128-to-127-2s-complement-and-not-fro) – akuzminykh Mar 08 '21 at 23:57

4 Answers4

0

8 bits can store up to 28 numbers.

It depends on the system and language, but on most systems, signed integers of maximum 8 bits would store {-128,127} range, that is -128...0...127, comprising all 256 (28) numbers.

Giorgi Tsiklauri
  • 6,699
  • 7
  • 29
  • 54
0

The standard notation would have the sign bit on the left, so 10000000 would be the most negative number, and 01111111 would be the most positive number.

If that seems weird, try the following thought exercise, which works for any number of bits. I'm going to use just 3 bits, to keep things brief.

            -4  -3  -2  -1   0   1   2   3   4   5   6   7 .
unsigned                    000 001 010 011 100 101 110 111
 signed     100 101 110 111 000 001 010 011

Note that (1) the eight 3-bit codes appear in the same order, it's just the "wraparound point" that differs, and (2) the positive numbers have the same bits in either representation.

0

The range for a signed 8-bit cell in decimal integers is -128 to 127.

Converting those to 2's complement binary:

 127 = 01111111
-128 = 10000000

Here is some information on 2's complement.

The range for an unsigned 8-bit cell would be 00000000 to 11111111 which is 0 to 255 in decimal.

mhawke
  • 75,264
  • 8
  • 92
  • 125
0

For a type of width n bits and using two's complement encoding.

  • the largest value is 2n-1-1
  • the smallest value is 2n-1

So for n = 8.

  • 2n-1-1 = 128-1 = 127 largest signed value for a byte
  • 2n-1 = 128 = -128 smallest signed value for a byte

or using bit shifting

1<<7 - 1 = 10000000 = 128 - 1 = 01111111  = 127
1<<7     = 10000000 = 128  =    10000000  = -128
WJS
  • 22,083
  • 3
  • 14
  • 32