represents 74

Download Report

Transcript represents 74

Computer Studies Today
19
Chapter
1
» Numbers within computers can be
expressed by
– Sign-and-magnitude
representation
– Two’s complement representation
Computer Studies Today
19
Chapter
2
Sign-and-magnitude Representation
» The most significant bit represents
the sign of the number:
1 for negative and 0 for positive
» The remaining bits represent the
magnitude of the number.
Computer Studies Today
19
Chapter
3
Bits for magnitude
Sign
bit
Computer Studies Today
19
Chapter
4
Computer Studies Today
19
Chapter
5
Binary Fraction in Sign-andmagnitude Representation
Binary fraction
0 0 0 1 1  1 1 0 = 11.112
1
0
1
2
=2 +2 +2 +2
Sign bit
= 2 + 1 + 0.5 + 0.25
= 3.7510
Computer Studies Today
19
Chapter
6
Binary fraction
1 1 0 1 1 1  1 1 = 10111.112
= (2 + 2 + 2
0
1
2
+2 +2 +2 )
= (16 + 4 + 2 + 1
+ 0.5 + 0.25)
= 23.7510
4
Sign bit
Computer Studies Today
19
Chapter
2
1
7
Two’s Complement Representation
» The most significant bit represents
a negative quantity.
» The magnitude of the number is the
sum of all digit values of the bits.
Computer Studies Today
19
Chapter
8
Most significant bit
Computer Studies Today
19
Chapter
9
» With the two’s complement
representation, it is easy to change
a positive number to the
corresponding negative number
and vice versa.
Computer Studies Today
19
Chapter
10
» The steps are as follows:
– Change all 0s to 1s.
– Add 1 to the rightmost digit.
Computer Studies Today
19
Chapter
11
» Change 2510 to 2510.
Computer Studies Today
19
Chapter
12
» Change 2310 to 2310.
Computer Studies Today
19
Chapter
13
Binary Fraction in Two’s
Complement Representation
Binary fraction
0 0 1 0 1  1 1 0 = 101.1102
2
0
1
2
=2 +2 +2 +2
Most significant bit
= 5.7510
Computer Studies Today
19
Chapter
14
Binary fraction
1 0 0 1  0 0 1 1 = 1001.00112
= 2 + 2 + 2
4
+2
= 6.812510
3
Most significant bit
Computer Studies Today
19
Chapter
0
3
15
Addition and Subtraction in Two’s
Complement Representation
–)
61
74
61
+) –74
–13
–13
00111101
+) 10110110
11110011 = 13
(valid)
» Subtraction can be done by
complementation and addition.
Computer Studies Today
19
Chapter
16
+)
61
74
00111101
+) 01001010
10000111 = 121 (invalid)
135
» The result is invalid because of an
overflow error.
Computer Studies Today
19
Chapter
17
–61
+) –74
–135
11000011
+) 10110110
1 01111001 = 121 (invalid)
The extra bit is discarded
because this is an 8-bit code.
» The result is invalid because of an
overflow error.
Computer Studies Today
19
Chapter
18
–61
–) –74
–61
+) 74
13
13
11000011
+) 01001010
1 00001101 = 13
(valid)
The extra bit is discarded
because this is an 8-bit code.
Computer Studies Today
19
Chapter
19
Comparisons between Sign-andmagnitude and Two’s Complement
Representation
Computer Studies Today
19
Chapter
20
» A number is composed of a
fraction part called a mantissa and
a power called an exponent.
» It represents numbers in a wider
range.
Computer Studies Today
19
Chapter
21
Sign of
mantissa
Sign of
exponent
Mantissa
15  14 13 12 11 10 9
8
7
6
5
Exponent
4
3
2
1
0
» Bit 0 to bit 7 represent the exponent
and bit 8 to bit 15 represent the
mantissa.
Computer Studies Today
19
Chapter
22
Normalisation
» A standardised floating point
representation.
» The first bit of the mantissa must
be non-zero.
Computer Studies Today
19
Chapter
23
» For example,
7.2510 = 111.012  2
0
= 0.111012  2
Mantissa
3
Exponent
0 1 1 1 0 1 0 0 0 0 0 0 0 0 1 1
Computer Studies Today
19
Chapter
24
Express 1001.0112 in floating-point
representation.
Computer Studies Today
19
Chapter
25
Solution
1001.0112 = 0.10010112  2
4
 The floating-point representation is:
0 1 0 0 1 0 1 1 0 0 0 0 0 1 0 0
Computer Studies Today
19
Chapter
26
Express 0.0000011112 in floatingpoint representation.
Computer Studies Today
19
Chapter
27
Solution
0.0000011112 = 0.11112  2
5
 The floating-point representation is:
0 1 1 1 1 0 0 0 1 0 0 0 0 1 0 1
Computer Studies Today
19
Chapter
28
Convert 1110000100000110, which is
in floating-point representation, into a
decimal value.
Computer Studies Today
19
Chapter
29
Solution
1110000100000110
= 0.11000012  2
= 0110000.12
6
= 48.510
Computer Studies Today
19
Chapter
30
Computer Studies Today
19
Chapter
31
» It means dropping off any extra
digits which cannot be
accommodate.
Computer Studies Today
19
Chapter
32
Truncate 123.88 to 4 significant
figures.
Computer Studies Today
19
Chapter
33
Solution
123.88
123.8
This causes a truncation error.
The error is 123.88  123.8 = 0.08
Computer Studies Today
19
Chapter
34
Truncate 0.10101012 to 6 bits.
Solution
0.10101012
0.1010102
Computer Studies Today
19
Chapter
35
» It means shortening a number by
deleting one or more digits in the
least significant positions.
Computer Studies Today
19
Chapter
36
» Increasing by one the remaining
far right digit if the truncated
digit is greater than or equal to
half of the number base.
Computer Studies Today
19
Chapter
37
Round 123.88 to 4 significant figures.
Computer Studies Today
19
Chapter
38
Solution
123.88
123.9
This causes a rounding error.
The error is 123.9  123.88 = 0.02
Computer Studies Today
19
Chapter
39
Round 0.10101012 to 6 bits.
Solution
0.10101012
0.1010112
Computer Studies Today
19
Chapter
40
» Since the fixed-point and floatingpoint representations of a number
have their own ranges, this causes
– An overflow error if the number
exceeds the range that can be
represented.
Computer Studies Today
19
Chapter
41
– An underflow error if the
number is too small to be
represented.
Computer Studies Today
19
Chapter
42