maxcc -4 years ago 136

C Question

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`

`11111111`

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

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**

Latest added