1

I understand to get two's complement of an integer, we first flip the bits and add one to it but I'm having hard time figuring out Tmax and Tmin?

In a 8-bit machine using two's compliment for signed integers how would I find the maximum and minimum integer values it can hold?

would tmax be =01111111? and tmin =11111111?

maxcc
  • 15
  • 1
  • 1
  • 3
  • [Why is the range of signed byte is from -128 to 127 (2's complement) and not from -127 to 127?](http://stackoverflow.com/q/11433789/995714), [signed two's complement arithmetic](http://stackoverflow.com/q/4941132/995714), [Why is the maximum value of an unsigned n-bit integer 2^n-1 and not 2^n](http://stackoverflow.com/q/5771520/995714) – phuclv Feb 28 '17 at 05:42

2 Answers2

4

You are close.

The minimum value of a signed integer with n bits is found by making the most significant bit 1 and all the others 0.

The value of this is -2^(n-1).

The maximum value of a signed integer with n bits is found by making the most significant bit 0 and all the others 1.

The value of this is 2^(n-1)-1.

For 8 bits the range is -128...127, i.e., 10000000...01111111.

Read about why this works at Wikipedia.

Ray Toal
  • 79,229
  • 13
  • 156
  • 215
0

Due to an overflow that would lead to a negative zero, the binary representation for the smallest signed integer using twos complement representation is usually a one bit for the sign, followed by all zero bits.

If you divide the values in an unsigned type into two groups, one group for negative and another positive, then you'll end up with two zeros (a negative zero and a positive zero). This seems wasteful, so many have decided to give that a value. What value should it have? Well, it:

  • has a 1 for a sign bit, implying negative;
  • has a 1 for the most significant bit, implying 2width-1 (128, in your example)...

Combining these points to reinterpret that value as -128 seems to make sense.

autistic
  • 14,356
  • 2
  • 33
  • 74