CompOrg W3 BCD and R..
Download
Report
Transcript CompOrg W3 BCD and R..
Computer Organisation 1
Encoding Real Numbers
(Numbers w Fractions)
Real Numbers in Computers
Packed Decimal aka Binary Coded
Decimal – BCD
Floating Point
Packed Decimal - BCD
Numbers can represented in the base 10 system
using binary encoding with four bits:
Packed Decimal – Binary Coded Decimal - BCD
However, it is possible to have 16 different
patterns with 4 bits, so this means that 6 of
the 4-bit patterns will remain unused. (The
equivalent of Hex A, B, .. F)
Thus, to represent 609 in BCD in two bytes:
0000 0110 0000 1001
0
6
0
9
Packed Decimal – Binary Coded Decimal - BCD
When we add two BCD integers, it is possible
to get a result which is not a valid BCD code.
Add 3 and 4
0011
+ 0100
-----0111
which is a valid BCD code
Packed Decimal – Binary Coded Decimal - BCD
Add 6 and 7
+
0110
0111
-----1101
- invalid BCD code
The result from this should be 3 carry 1. This
is achieved in the computer by adding a 6 to
the invalid code.
Packed Decimal – Binary Coded Decimal - BCD
Thus, the computer has to test for an
invalid BCD code, eg 1101
1101
+ 0110 that is, Add 6
------1 0011 that is, BCD 3, and carry 1
BCD applications
BCD is used in calculators and business
applications (COBOL programming
language)
Use of BCD avoids the conversion
process (from decimal to binary and vv)
at input and output
BCD also avoids the problem of
terminating fractions (0.33333 etc)
Floating Point Notation
A standard 32-bit floating point number
consists of 4 parts. These are
the sign - 1 bit
exponent - 8 bits
the fraction - 23 bits
The base - always 2, so it's implied and
not stored
Floating Point Notation
Look at a base 10 floating point number first:
23.56 x 10^4
First of all normalise it to be 0.2356 x 10^6
We call 0.2356 the fraction, the mantissa, or the
significand.
10 is said to be the base;
6 is the exponent;
And the implied sign is plus, in this case.
Floating Point Notation
We can write floating point numbers in many
ways, for example:
3246.5 x 10^0 = 3.2465 x 10^3 = 0.32465 x
10^4
However, to simplify arithmetic and comparisons,
the number is always normalised so that the most
significant digit comes after the point.
In decimal numbers the MSD could be any digit
from 1 to 9.
Floating Point Notation
When Normalisation is carried out on computer
floating point binary numbers, the most significant
digit is always one. That is, the MSD in the fraction
part of the number is always 1.
This leading 1 is not stored, but stripped off to add
extra precision to the stored fraction. For example, if
the mantissa is
0.110111101 etc
it is stored as
0.10111101 etc
Floating Point Notation
Convert - 1351.755 to floating point binary.
Ignore the sign for the present. Take 1351
and convert it to binary; then take 0.755 and
convert to binary, then join these parts.
1351 in binary is found by successive division
by 2, and saving the remainders:
Floating Point eg 1351.755
1351/2 = 675 r 1
675/2 = 337 r 1
337/2 = 168 r 1
168/2 = 84 r 0
84 /2
= 42 r 0
42/2
= 21 r 0
21/ 2
= 10 r 1
10/2
=5r0
5/2
=2r1
2/2
=1r0
1/2
= 0 r 1 msb
So, 1351 = 101 0100 0111
Floating Point eg 1351.755
0.755 is converted to binary by successive multiplication of the
decimal fraction by 2, until it reduces to zero or repeats
.755 x 2
msb
1 .510 x 2
1 . 02 x 2
0 . 04 x 2
0 . 08 x 2
0 . 16 x 2
0 . 32 x 2
0 . 64 x 2
1 . 28 x 2
0 . 56 x 2
1 . 12 x 2
0 . 24 x 2 Result : 0.11000001010 (and loose
change)
Floating Point eg 1351.755
Thus - 1351.755 is represented in binary by
-101 0100 0111. 11000001010
Normalised, this is
- . 101 0100 0111 1100 0001 0100 x 2^11
So the exponent for this number is 11
(decimal), which is 1011 binary. In Excess
128, this is 1000 1011.
Floating Point eg 1351.755
The fraction part will be stored, not as
101 0100 etc
But, stripping off the MSB, as
01 0100 etc
The sign is negative, so the sign bit will
be 1
Floating Point eg 1351.755
-1351.755 is stored as a 32 bit floating
point number :
S Expnt.
Fraction (underlined)
1 1000 1011 010 1000
1111 1000
0010 1000 <--- LSB
Floating Point eg 2.5
Another example: Find the 32-bit FP binary
representation of +2.5
2 in binary is 10; 0.5 is 0.1; this gives 10.1 in binary.
10.1 = .101 x 2^2
Sign bit is 0
Exponent is 1000 0010
Fraction is held as 010 0000 0000 etc
S Expnt.
Fraction (underlined)
0 1000 0010 010 0000
0000 0000 0000 0000 LSB
Floating Point
Floating point formats
A standard format for floating point
representation in computers called the IEEE
754 standard was established in 1985.
Single-precision FP occupies 32 bits with an
8-bit excess 127 (NOT 128) and 23-bit
fraction; exponent values of all zero or all 1s
are reserved for special cases.
Double precision FP occupies 8 bytes - 64
bits, with an eleven bit (excess 1023)
exponent and 52 bit fraction.
Floating Point
Some examples in IEEE single precision:
Value
Sign
Exp
+1.101 x 2^5
0
1000 0100
-1.01011 x 2^–126 1
0000 0001
+1.0 x 2^127
0
1111 1110
+0
0
0000 0000
-0
1
0000 0000
+infinity
0
1111 1111
+NaN
0
1111 1111
Fraction
1010000 etc
0101100 etc
0000000 etc
0000000 etc
0000000 etc
0000 0000 etc
001100010 etc
Floating Point
Infinity has a representation with the
exponent containing the reserved bit pattern
all 1s, all-zero fraction, and is useful for
handling overflow situations or divisions of
some number (not zero) by zero.
NaN - not a number, is useful for the
undefined results of dividing infinity by
infinity, or zero by zero.
Overflow occurs in FP representation if the
exponent overflows.