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.
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.
negative numberA number less than zero. 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 binaryA number system that contains two symbols, 0 and 1. Also known as base 2. number is called the most significant bit (MSB)The place in a binary number which has the highest value in denary.. It holds the highest place value and is the ‘sign’ bitThe smallest unit of data in computing represented by a 1 in binary.. In a byteA unit of data containing 8 bits., 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.
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 (denaryThe number system most commonly used by people. It contains 10 unique digits 0 to 9. Also known as decimal or base 10.). 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
-128
64
32
16
8
4
2
1
1
1
0
0
0
1
0
0
-128
1
64
1
32
0
16
0
8
0
4
1
2
0
1
0
Result: (1 × -128) + (1 × 64) + (1 × 4) = -60
Example: Two’s complement binary number 01100100
-128
64
32
16
8
4
2
1
0
1
1
0
0
1
0
0
-128
0
64
1
32
1
16
0
8
0
4
1
2
0
1
0
For a positive number, the conversion is exactly the same as eight-bit binary numbers. Remember that the MSB is always 0.