5.4. Binary Number System
5.4. Binary Number System
www.pmt.education
Specification:
www.pmt.education
4.5.4.6 Absolute and relative errors:
Be able to calculate the absolute error of numerical data stored and
processed in computer systems.
Be able to calculate the relative error of numerical data stored and
processed in computer systems.
Compare absolute and relative errors for large and small magnitude
numbers, and numbers close to one.
www.pmt.education
Signed and unsigned binary
1011
The string of 0
s and 1
s above is a binary number. It could be either signed or unsigned,
and there’s no way to work that out. A computer has to be told whether a number is signed
or unsigned.
Unsigned binary numbers can only represent positive numbers. Signed binary allows for
the representation of negative numbers using binary.
There is a pattern to the range of numbers that can be represented by a given number of
bits. For n bits, there are 2n
possible permutations of the bits, giving a range of decimal
numbers from 0to 2-1
n
.
For example, with eight bits, the decimal numbers 0to 255(= 28
-1
) can be represented.
1. 0 +
0 + 0 = 0
2. 0 +
0 + 1 = 1
3. 0 +
1 + 1 = 10
4. 1 + 1 + 1 = 11
Make sure you understand these rules and adding binary numbers will be easy.
www.pmt.education
Example: Add the unsigned binary integers 1011and 1110
.
Place the two binary numbers above each other so that the
1 0 1 1
digits line up.
+ 1 1 1 0
Starting from the least significant bits (the right hand side),
1 0 1 1
add the values in each column and place the total below.
+ 1 1 1 0 For the first column (highlighted), rule 2 from above
applies.
1
Finally, the result is read off from the full size numbers at
1 1 0 0 1 the bottom of each column. In this case, 1011 + 1110 =
11001 .
After carrying out binary addition, it’s a good idea to check your answer by converting to
decimal if you have time. In this example, 1011 2 (11
10) + 1110
2 (14
10) = 11001
2 (25
10) so
we haven’t made any mistakes.
www.pmt.education
Multiplying two unsigned binary integers
When multiplying unsigned binary numbers, write out one of the two numbers starting
under each occurrence of a 1 in the second number and then add the contents of the
columns.
+ 1 0 1 0 0 0 0
1 1
1
0 1 1 1 0
As with binary addition, binary multiplication can be checked by converting to decimal. In
this example, 10112 (1110) × 10102 (1010) = 11011102 (110
10) so the multiplication has
worked correctly.
www.pmt.education
Signed binary with two’s complement
There are a few different coding schemes that can be used for signed binary. AQA uses
one called two’s complement to allow for the representation of both positive and negative
numbers in binary.
When using two’s complement, the most significant bit of a number is given a negative
place value. For example, with four bits, the place values would be:
-8 4 2 1
This allows negative numbers to represented like so:
-8 4 2 1
1 0 1 1
-8+ 2 + 1 = -5
www.pmt.education
Range of two’s complement numbers
Given a certain number of bits, the range of a two’s
-8 4 2 1
complement signed binary number includes both positive
and negative values.
0 1 1 1
For example, with four bits, the largest positive value that
can be represented is 7 and the most negative number that 4 + 2 + 1 = 7
can be represented is -8 as shown on the right hand side of
the page.
More generally, with n bits, the range of a two’s complement -8 4 2 1
signed binary number is from 2 -1to -2
n-1 n-1
.
1 0 0 0
= -8
Binary can be used to represent numbers with a fractional part. There are two ways of
doing this, one uses fixed point form and the other uses floating point form.
Standard binary place values are used for columns before the binary point, and the
columns behind the binary point start at ½, then ¼ and ⅛ etc.
For example, with 8 bits split evenly with four bits before and after the binary point, the
number 11.312510 can be represented in binary as 10110101 .
8 4 2 1 • 1
2
1
4
1
8
1
16
1 0 1 1 0 1 0 1
1 1
8 + 2 + 1 + 4
+ 16
= 11.3125
www.pmt.education
Floating point binary (binary to decimal)
Floating point binary is comparable to scientific notation in that a number is represented as
a mantissa and an exponent. In scientific notation, the number 3,100,000 could be written
as 3.1×106 where 3.1 is the mantissa and 6 is the exponent.
In exam questions on floating point numbers, both the mantissa and exponent will be
represented using two's complement signed binary.
In floating point binary, a number of bits are allocated to the mantissa the remaining bits
form the exponent. For example, with 5 bits for the mantissa and three for the exponent:
0 1 1 0 1 0 1 1
Mantissa Exp.
In order to convert from floating point form to decimal, first convert the exponent to
decimal. In this example, 0112 = 3 .
10
Next, treating the number as if there were a binary point between the first and second
digits of the mantissa, move the binary point the number of positions specified by the
exponent. In this case, the binary point moves three positions.
Now treat the mantissa as a fixed point binary number, with the binary point fixed in the
position specified by the exponent.
− 8 4 2 1 • 1
2
0 1 1 0 1
1
4 + 2 + 2
= 6.5
As shown above, the result of converting the floating point binary number 01101011to
decimal (with a five bit mantissa and three bit exponent) is 6.5
.
www.pmt.education
Floating point binary (decimal to binary)
In order to convert a decimal number to a floating point binary number, you must first
convert your decimal number to fixed point binary.
14.625 is smaller than 16, so we need columns before the binary point for -16, 8, 4 and 2.
0.625 = ½ + ⅛ so we need columns after the binary point for ½, ¼ and ⅛.
− 16 8 4 2 1 • 1
2
1
4
1
8
0 1 1 1 0 1 0 1
Now that we have a fixed point representation of our decimal
number, we have to normalise the number. In order to be
normalised, a floating point number must start with 01(for a
positive number) or 10(for a negative number). As explained
above, when converting from floating point to decimal, the
binary point is assumed to be between the first two digits in
the mantissa. In this case, we must add a leading 0and
move the binary point four positions to the left.
Our exponent must therefore be four, and positive because we moved the decimal point to
the left. If the point had moved to the right, our exponent would be negative. Converting
this exponent into binary gives us 0100 .
We now have our mantissa as 01110101and our exponent as 0100 . Therefore 14.62510
= 0111010101002in floating point notation with an eight bit mantissa and a four bit
exponent.
www.pmt.education
Rounding errors
There are some decimal numbers that cannot possibly be represented exactly in binary,
even with the use of fixed point or floating point notation. A bit like ⅓, which can only be
represented in decimal as 0.3333 …, there are some numbers which binary can only
approximately represent.
There are many numbers that binary cannot accurately represent, one of which is 0.110
which is 0.00011001100110011 … in binary. For this reason, both fixed point and
floating point representations of decimal numbers may be inaccurate.
You can calculate absolute and relative errors in order to see how close a particular
number is to an actual value.
The binary 1110.1is equal to 14.5 , so the absolute error can be calculated like so:
10
14.6
10 - 14.5
10 = 0.1 .
10
www.pmt.education
Relative error calculation
A relative error is a measure of uncertainty in a given value compared to the actual value
which is relative to the size of the given value. A relative error can be calculated using the
formula:
absolute error
relative error = actual value
This formula gives a relative error as a decimal, but can give a percentage if the result is
multiplied by 100.
The binary 1100.011is equal to 12.37510. The absolute error is therefore 0.025. Using
the formula, we can calculate the relative error.
0.025
relative error % = 12.4 × 100 = 0.2016 to 4 s.f .
Although both fixed point and floating point perform the same function of representing
numbers with fractional parts in binary, they each have their own relative advantages and
disadvantages.
Floating point allows for the representation of a greater range of numbers with a given
number of bits than fixed point. This is because floating point can take advantage of an
exponent which can be either positive or negative. The number of bits allocated to each
part of a floating point number affects the numbers that can be represented. A large
exponent and a small mantissa allows for a large range but little precision. In contrast, a
small exponent and a large mantissa allows for good precision but only a small range.
In a similar way, the placement of the binary point in fixed point notation determines the
range and precision of the numbers that can be represented. A binary point close to the
left of a number gives good precision but only a small range of numbers. However, move
the binary point to the right and the range is increased while decreasing precision.
www.pmt.education
Normalisation
Floating point numbers are normalised in order to provide the maximum level of precision
for a given number of bits. Normalisation involves ensuring that the a floating point
numbers starts with 01(for a positive number) or 10(for negative numbers).
0 0 0 1 1 0 1 0 0 1 0 1
Mantissa Exponent
Because we’ve made the mantissa bigger by shifting the bits two positions to the left, we
must reduce the exponent by two so as to ensure the same number is still represented.
The current exponent is 510 so, subtracting two, the new exponent must be 310 which is
00112 in binary.
0 1 1 0 1 0 0 0 0 0 1 1
Mantissa Exponent
www.pmt.education
Underflow and overflow
Underflow and overflow are two types of error that can occur when working with binary.
Underflow
Underflow occurs when very small numbers are to be
represented but there are not enough bits available. For
example, the number 0.015625 10 can be represented in
fixed point binary as 0000001 2 with one bit before the binary
point and six bits after the binary point. However, if only 5 bits
are available after the binary point, the number would be
represented as 000000 2 which is 010
.
Overflow
Overflow occurs when a number is too large to be represented with the available bits.
Overflow is particularly important when using signed binary.
Example: Using 8 bit two’s complement signed binary, perform the operation 127 + 1
.
0 1 1 1 1 1 1 1
+ 0 0 0 0 0 0 0 1
1
1
0
1
0
1
0
1
0
1
0
1
0
1
0
As the working above shows, the result of 01111111+ 00000001in two’s complement
signed binary is 10000000
. Converting these numbers to decimal, we have that 127 + 1
= -128which obviously isn’t right. Overflow has occurred.
www.pmt.education