Before we move on, I just wanted to take a moment to look at another peculiarity of using binary numbers, the concept of wrap-around.

Wrap-around is very similar to the odometer on a vehicle. Assume the odometer on our example vehicle has 6 digits to represent the mileage. As we clock up the distances, the value on the odometer climbs and eventually reaches the maximum number that those six digits can represent… 9999998, 999999….

At the point that the mileage moves through 999999, the next number that is displayed is 000000, all zeros and the odometer starts counting up again i.e. it wraps around.

Now, take that very same idea and apply it to the binary numbers we have been talking about.

Imagine that we have a single byte containing an unsigned number to which we are continuously adding 1.

Eventually we will get to the maximum number that those bits can collectively represent (11111111_{2}).

As we attempt to add the next 1, the resulting binary number would normally be 100000000_{2} but as we only have 8 bits in which to represent it the 1 that is carried into the 9^{th} column is dropped, leaving the number 00000000_{2}. It effectively wraps around to the minimum value that can be stored.

This phenomenon also occurs when we count down.

As we keep subtracting one from our 8 bits of data and reach the smallest possible value (00000000_{2} or 0_{10}) the next 1 that is subtracted causes all the bits to flip and we get 11111111_{2} or 255_{10,} the maximum number that can be stored.

Keep an eye out for this when you are reaching the maximum and minimum ranges that can be stored in a given number of bits.

Image credit: http://flic.kr/p/2bn9mu