Transcript week 3
Lecture 3
Number Representation 2
This week
–
–
–
–
Recap Addition
Addition circuitry
Subtraction of integers in binary
Representing numbers with fractional parts
For example 1010
+
0011
_____
=
1101
1
^
Carry __|
Using these rules pairs of numbers plus a carry
bit are added together starting for the right.
When there is no carry from the previous
addition operation the carry bit plays no part in
the calculation it is as if the calculation was
just bits A and B. When carry bit is set (a carry
from the previous operation) the calculation is
A+B+Carry. The carry bit after the final
addition operation is ignored.
Binary subtraction
Binary subtraction is performed by converting
the second number into it’s two’s complement
and adding. So there is not a need for a
subtracting circuit.
As an example: 14-6
Subtraction Example
Number A=14
00001110
Number B=6
00000110
Reverse bits in Number B
11111001
+1
11111010
B 2’s Complement = C
11111010
14
00001110
2’s Complement of 6
11111010
add
8
00001000
How do we represent numbers with
fractional parts?
One way would to say that so many bits will represent
whole numbers, and the remainder will represent
fractional number such as 0.5, 0.25 or 0.125. An
example of this could be the three most significant bits
are used to represent whole numbers, the remaining
bits represent 1/powers of 2 (e.g. 1/2, 1/4, 1/8, 1/6).
The binary point (equivalent to a decimal point in
decimal numbers) is between 1 and 1/2.
4
2
1
½
¼
1/8
1/16
1
0
1
1
0
1
0
Therefore, from table 1 this number 101.101
represents the decimal number
4+1+0.5+0.125=5.625. So the number can be
split into two parts the whole number part (in
this case 101 (which is 5 in decimal)) and a
fractional part 101.
Floating-point numbers
Often we want to represent very small, very large
numbers or numbers with fractional parts. For
example, 33550000 or 0.00000001451 the binary
format we have already met is not capable, so we need
another form. One way of doing this is scientific
notation where these numbers are split into two parts
a number with a decimal point within it (called the
mantissa) and a power of 10 (called the exponent).
Fixed Notation
Scientific
Notation
Mantissa
Exponent
33550000
0.3355x108
0.3355
8
0.00000001451
0.1451x10-7
0.1451
-7
So for example, the decimal number 5.625 could be
represented as 101.101. If we use this mantissa and
exponent idea, it could also be written as 0.101101x23
(Normalised) where the exponent shows the true
position of the binary point (no longer a decimal point,
as we are not using the decimal system) relative to the
current position.
Because the binary point can be altered depending on
the magnitude of the exponent, it often refereed to as
a floating-point representation.
IEEE standard (single precision)
Sign
Exponent
Mantissa
Bit 31 Bits 23-30
Bits 0-22
-ve
13110
0.26562510
1
10000010
01000100000000000000000
Features with floating point
representation
Gives a wide range of numbers
It is not precise
Precision and Range can be improved using
more bits (64 bits in Double precision)
–
–
–
Bit 63 for sign,
bits 52-62 for exponent
Bits 0 to 51 for mantissa
Summary
There is no subtraction circuit, but there is
addition circuitry.
Subtract of binary integers can be converting a
positive number into 2’s complement.
Floating point number:
((sign)x(1+stored mantissa))x2(stored exponent-127)
IEEE standard (single precision)
Sign
Exponent
Mantissa
Bit 31 Bits 23-30
Bits 0-22
-ve
13110
0.26562510
1
10000010
01000100000000000000000
Sources for further reading
Dick D(2003) pages 93-103.
Chalk et al (2004) pages 20-23
Burrel (2004) Chapter 2 - pages 25 -34
Tannebaum (2005) pages 691-699