# Two's complement maximum and minimum

If we have a binary sequence that is $x$ bits long, what are the minimum and maximum that can be represented in two's complement form?

The maximum is $2^{x-1}-1$, and the minimum is $-2^{x-1}$.

But why? How can it be shown that this is the case?

• Should probably go in computer science. Also this is incredibly easy to google. But just to answer you. b00 = 0 b01 = 1 b10 = -1 b11 = -2 – lm317 Dec 16 '14 at 21:09
• umm... I think b11 is -1 – PkP Dec 16 '14 at 21:19
• lm317 you are mistaken. b10 is -2, b11 is -1 b00 is 0, and b01 is 1 – Jotorious Dec 16 '14 at 21:21
• +1 for such a fun and easy question for once, while at the same time being a bit philosophic also – PkP Dec 16 '14 at 21:22
• @PkP Philosophic? Really? It would be if it had an42 inside.. – Eugene Sh. Dec 16 '14 at 21:35

Look at 3 bits representation:

000 = 0
001 = 1
010 = 2
011 = 3
100 = -4
101 = -3
110 = -2
111 = -1


Half of the numbers are starting with '1', which is the sign bit. So half of the numbers are negative. It means that we have $(2^x)/2 = 2^{(x-1)}$ negative numbers. The rest are positive and zero.

For x bits, there are 2x values.

In one's complement system there are two zeros and 2x-1 - 1 positive and the same number of negative values.

In two's complement system those are assigned so that there is only one zero and one more negative value than there are positive values.

The two's complement system is in use, because it stems from how simple hardware naturally operates. Think for example you car's odometer, which you have resetted to zero. Then put the gear on reverse, and drive backwards for 1 mile (Please don't do this in reality). Your odometer (if it's mechanical) will roll from 0000 to 9999. The two's complement system behaves similarly.

Edit: Added the picture to harvest an amazing amount of points from this question

• Odometer usually don't work that way except perhaps on very old cars. Authoritative reference: Ferris Bueller's Day Off (and lots of internet posts). – Spehro Pefhany Dec 16 '14 at 22:00
• @SpehroPefhany, Works like it in my 1994 Nissan :D – PkP Dec 16 '14 at 22:01

For a binary sequence of X bits there are 2^x possible values.

Using unsigned integers to represent these then, you have the set from 0, 1, ...(2^x)-1. If one wanted to effectively shift the values down to have half negative and half positive, you would subtract 2^(x-1) (which is half the range) from every value, this giving you 0 - 2^(x-1),....,(2^x)-1 - (2^(x-1)).

Reorganizing the later term into 2^x- 2^(x-1) - 1 and recognizing, that y^x - y^(x-1) = y^(x-1), you then have your range, -(2^(x-1))...2^(x-1)-1.

This is done in implementation by negating the MSB, which by virtue of it's place value is half the range.

• I made a mistake. y^x-y^(x-1) = y^(x-1) only works when y=2. it cant be generalized to every integer. 2^4 - 2^3 = 2^3, but only because the base is 2. 3^3 = 3^2 != 3^2 – Jotorious Dec 16 '14 at 23:08

In two's compliment, the most significant bit (furthest left) is reserved for the sign of the number, so that's why it's x-1. The reason that it is $2^{x-1} -1$ for positive numbers is that one of these is used for zero, while in the negative numbers, we start right out at -1.

• This is not right. In twos complement the MSB holds the negative of the value of the highest place value. 1011 is -8 + 0 + 2 + 1 = -5. twos complement is identical to unsigned binary, except the MSB is negated. – Jotorious Dec 16 '14 at 21:18
• Kypalmer, @Jotorious, You're both right, although kypalmer's explanation is a bit unusual (which I actually like a lot) :D – PkP Dec 16 '14 at 21:25
• I think you're meaning $2^{x-1}$ there, aren't you? – user17592 Dec 16 '14 at 21:45
• Thanks, Yes that should have been in the exponent. – kypalmer Jan 23 '15 at 1:26