Negative numbers: Sign and magnitude

Computers sometimes need to work with negative numbers.

Integers can be encoded so that they can be positive or negative numbers. Integers that can be either positive or negative are signed numbers.

One way to represent negative numbers is through sign and magnitude. In this method, the bit at the far left of the bit pattern - the sign bit - indicates whether the number is positive or negative. The rest of the bits in the pattern store the size of the number (called its magnitude).

For example, with an 8-bit pattern, the first bit would be used to indicate positive or negative.0 can indicate a positive number and a 1 can indicate a negative number. The other seven bits would be used to store the actual size of the number.

For example, 10001001 could represent -9:

  • the first bit, 1, indicates a negative number
  • the other seven bits indicate the number, 0001001 = 9

The smallest possible number using this method of representation is -127 (or 11111111) and the largest possible number is +127 (or 01111111).