Binary and data representation - EdexcelNegative numbers

All data in a computer is represented in binary, whether it is numbers, text, images or sound. The computer software processes the data according to its content.

Part ofComputer SciencePrinciples of computer science

Negative numbers

Binary can be used to represent both positive and negative numbers.

Unsigned and signed integers

A signed integer is a bit used to represent the sign of the number. The left-most value in a binary number is called the most significant bit (MSB). It holds the highest place value and is the ‘sign’ bit.

An unsigned integer doesn’t use a bit to represent the negative symbol or a negative number. In a byte, that will be the place value for 128 or 2 7.

can be represented in two ways:

  • sign and magnitude
  • two's complement

Sign and magnitude

In sign and magnitude, a 0 in the MSB indicates that the number is positive, and a 1 that the number is negative. The left-most value in a number is called the . It holds the highest place value and is the ‘sign’ . In a , that will be the place value for 128 or 27. In sign and magnitude, a 0 in the MSB indicates that the number is positive and a 1 that the number is negative.

Sign and magnitude conversion to denary

Converting a sign and magnitude number is exactly the same as any binary number. However, the value in the MSB is ignored as part of calculation.

Example: signed binary number 01101100

1286432168421
01101100
1280
641
321
160
81
41
20
10

Result: (1 × 64) + (1 × 32) + (1 × 8) + (1 × 4) = 108.

The value in the MSB is 0 so this is a positive number.

Example: signed binary number 11011100

1286432168421
11011100
1281
641
320
161
81
41
20
10

Result: (1 × 64) + (1 × 16) + (1 × 8) + (1 × 4) = -92.

The value in the MSB is 1 so this is a negative number.

Since there are now only seven bits available, the largest positive number that can be held in this format is 01111111 (binary) or +127 (). The largest negative number is 11111111 (binary) or -127 (denary).

Some problems with sign and magnitude are that there are two values for 0 (10000000 and 00000000), a bit is wasted and there are problems with addition since it is not always clear how to deal with the sign bit.

Two’s complement

In two’s complement negative numbers, the MSB is a negative value and also a sign bit.

Example: Two’s complement binary number 11000100

-1286432168421
11000100
-1281
641
320
160
80
41
20
10

Result: (1 × -128) + (1 × 64) + (1 × 4) = -60

Example: Two’s complement binary number 01100100

-1286432168421
01100100
-1280
641
321
160
80
41
20
10

For a positive number, the conversion is exactly the same as eight-bit binary numbers. Remember that the MSB is always 0.

Result: (1 × 64) + (1 × 32) + (1 × 4) = 100