maxcc maxcc -4 years ago 136
C Question

Tmax and Tmin of two's complement

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
?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download