Professional Documents
Culture Documents
INTRODUCTION TO
COMPUTER SYSTEMS
Chapter 2: Digital Logic and Numerical Data Representation
1
Chapter Outline
2.1 Alphanumeric character data representation
2.2 Numbering systems frequent come out
2
2.1 Alphanumeric Character Data Representation
In the computing environment, computer uses alphanumeric character
data code / representation to map the data to strings of binary digits.
Major types of alphanumeric character data representation used are:
EBCDIC ASCII
Extended Binary Coded Decimal American Standard Code for Info
Interchange Code Interchange
Founder IBM Other hardware manufacturer
3
2.2 Numbering Systems
Numbering system is essential to illustrate how numbers work, the nature
of counting and the arithmetic computations performed,
Human count and perform arithmetic using decimal (base 10 number)
while computer uses binary system (base 2).
To represent a binary-coded values in computing and digital electronics,
octal numbers (base 8) and hexadecimal numbers (base 16) are used.
4
2.2 Numbering Systems
5
2.2 Numbering Systems
= 2110 3 3 011
4 4 100
5 5 101
6 6 110
7 7 111
7
2.2 Numbering Systems
Base 10 Base 2 Base 8 Base 16
10000001001010101010101
01101010101010101001011
11010101010101010101010
01111111110000010101010
8
2.2 Numbering Systems
9
2.3 Arithmetic Conversions
41(base 5) ---> dec 25d ---> binary
(source) (destination)
Possible Conversions = (4x5^1) + (1x5^0) <-- 1m
= 20+1 /destination=/2
= 21d <-- 1m
2)25
A31o ---> dec 2)12-1
==> invalid 2) 6-0
Bin 2 ==> A is out of range in base 8 2) 3-0
1-1
Ans: 11001b
11
2.3 Arithmetic Conversions
12
2.3 Arithmetic Conversions
13
2.3 Arithmetic Conversions
1112 = 78
14
2.3 Arithmetic Conversions
E.g.: Base 2 Base 16
1112 = 01112
= 716
15
2.3 Arithmetic Conversions
16
2.3 Arithmetic Conversions
17
2.3 Arithmetic Conversions
3510
2) 35
2) 17 – 1
2) 8 – 1
2) 4 – 0
2) 2 – 0
1–0 3510 = 1000112
18
2.3 Arithmetic Conversions
13510
8) 135
8) 16 – 7
2–0
13510 = 2078
19
2.3 Arithmetic Conversions
815110
16) 8151
16) 509 – 7
16) 31 – 13 (D)
1 – 15 (F) 815110 = 1FD716
20
2.4 Arithmetic Operations
Binary Addition
21
2.4 Arithmetic Operations
Octal Addition
28
28 58
08 28 58 78
+ 78 + 78 + 78 + 38
78 118 168 218
22
2.4 Arithmetic Operations
Hexadecimal Addition
B16
216 A16
116 716 A16 C16
+ C16 + 716 + 716 + 116
D16 E16 1316 2216
23
2.4 Arithmetic Operations
Binary Subtraction
Remaining value after borrowed to right Borrowed: 2 + 0 = 2
02 0 2
112 102 1012
- 12 - 12 - 112
102 12 102
24
2.4 Arithmetic Operations
Octal Subtraction
Remaining value after borrowed to right Borrowed: 8 + 2 = 10
0 8
78 128 7058
- 18 - 78 - 2138
68 38 4728
25
2.4 Arithmetic Operations
Hexadecimal Subtraction
Remaining value after borrowed to right Borrowed: 16 + 7 = 23
0 16
26
2.4 Arithmetic Operations
Binary Multiplication
27
2.4 Arithmetic Operations
Octal Multiplication
78 128 3158
x 58 x 58 x 228
438 51 1010 6 2 1010
= 6 28 6 2 1010
61 81 121 1010
= 7 1 5 28
28
2.4 Arithmetic Operations
Hexadecimal Multiplication
29
2.5 Signed and unsigned number representation
30
2.5 Signed and unsigned number representation
1 001 00112
31
2.5 Signed and unsigned number representation
32
2.5 Signed and unsigned number representation
2.5.3 Two's Complement
Objective:
To represent negative value
To perform subtraction
Characteristics: The sign of the number is a natural result of the method.
Therefore, it does not need to be handled separately.
Steps:
1. One’s complement: Perform inversion. i.e. change 1’s to 0’s and 0’s
to 1.
2. Adding 1 to the result of One’s complement.
As the computer stores data in byte basis, therefore 8 bit system is
normally used.
33
2.5 Signed and unsigned number representation
2.5.3 Two's Complement
E.g.:
1010 = 0000 10102
One’s complement = 1111 01012
Add 12 = 12 +
Two’s complement = 1111 01102
= - 27 + 26 + 25 + 24 + 22 + 21
= - 1010
34
2.5 Signed and unsigned number representation
35
2.5 Signed and unsigned number representation
2.5.4 Overflow Flag & Carry Flag
Overflow
❑ Occurs when the result of an arithmetic operation does not fit into the
fixed number of bits available for the result.
❑ Occur only when both operands have the same sign.
❑ Detected by the fact that the sign of the result is opposite of both
operands.
❑ Stored in overflow flag (OF)
Carry
❑ Occurs when the result of an arithmetic operation exceeds the fixed
number of bits allocated, without regard to the sign.
❑ The carry bit is ignored in single precision 2’s complement addition and
subtraction.
❑ Detected when extra ‘1’ bit is generated.
❑ Stored in carry flag (CF) 36
2.5 Signed and unsigned number representation
2.5.4 Overflow Flag & Carry Flag
Overflow
❑ E.g.:
6410 0100 00002
+ 6510 + 0100 00012
12910 1000 00012 = -12810 + 110 = 12710
i.e. 129 does not fit into the number of bits available. Therefore,
OVERFLOW occur.
Since 12910 ≠ -12710 , this is invalid.
37
2.5 Signed and unsigned number representation
2.5.4 Overflow Flag and Carry Flag
Carry
E.g.:
10610 0110 10102
+ (- 2)10 + 1111 11102
10410 (1)0110 10002
= 0110 10002
= 10410
Carry ignore
38
2.5 Signed and unsigned number representation
2.5.4 Overflow Flag & Carry Flag
Example: Addition of 4-bit 2's complement
40
2.6 Floating-point number representation & standard
±0 . 12345 x 10 ±5
Sign
location Magnitude Base sign of Exponent
of decimal point / Mantissa exponent
41
2.6 Floating-point number representation & standard
42
2.6 Floating-point number representation & standard
44
2.6 Floating-point number representation & standard
45
2.6 Floating-point number representation & standard
46
2.6 Floating-point number representation & standard
10011.101112
0001 0011 . 1001 10002
1 3. 9 8 16
47
2.6 Floating-point number representation & standard
48
2.6 Floating-point number representation & standard
4 F 5. 0 916
0100 1111 0101 . 0000 10012
49
2.6 Floating-point number representation & standard
50
2.6 Floating-point number representation & standard
2.6.3 Floating Point Representations
Floating Point Representation - SEEMMMMM
In SEEMMMMM format
1 digit for sign.
2 digits for exponent.
5 digits for mantissa, the decimal point location is assumed to be
located at the beginning of mantissa.
Excess -48 -49 50 51 52
Exponent -2 -1 0 1 2
Excess-N notation
N is the chosen middle value.
E.g.: Excess-50 allow a magnitude ranges as follow:
0.00001 x 10-50 < Number < 0.99999 x 1049
51
2.6 Floating-point number representation & standard
53
2.6 Floating-point number representation & standard
2.6.3 Floating Point Representations
Floating Point Representation - SEEMMMMM
❑ Normalization and formatting
❑ E.g.: Given 246.8035, normalize it and represent it in SEEMMMMM format.
Assume that:
Excess-50 is applied.
A 0 represents positive and 5 represents negative.
❑ Steps:
1. Add exponent : 246.8035 x 100
2. Position decimal point : 0.2468035 x 103
3. Already normalized, no adjustment is required.
4. Trim mantissa to 5 digits : 0.24680 x 103
5. Convert the number : 05324680
54
2.6 Floating-point number representation & standard
2.6.3 Floating Point Representations
Floating Point Representation - SEEMMMMM
❑ Normalization and formatting
❑ E.g.: Given -1255 x 10-3, normalize it and represent it in SEEMMMMM format.
Assume that:
Excess-50 is applied.
A 0 represents positive and 5 represents negative.
❑ Steps:
1. The number is already in exponential form.
2. Position decimal point : - 0.1255 x 101
3. Already normalized, no adjustment is required.
4. Trim mantissa to 5 digits : -0.12550 x 101
5. Convert the number : 55112550
55
2.6 Floating-point number representation & standard
56
2.6 Floating-point number representation & standard
2.6.3 Floating Point Representations
Floating Point Representation - SEEMMMMM
❑ Addition and subtraction
Assume that:
Excess-50 is applied.
A 0 represents positive and 5 represents negative.
E.g.: Add the 2 floating-point numbers.
05199520
+ 04967850
Align exponents = 05199520
By adding 2 zeros in front to mantissa = 0510067850 +
Add mantissa, (1) indicates a carry = (1)0019850
Carry requires right shift of exponent = 05210019(850)
Round = 05210020
57
2.6 Floating-point number representation & standard
2.6.3 Floating Point Representations
Floating Point Representation - SEEMMMMM
❑ Addition and subtraction
Assume that:
Excess-50 is applied.
A 0 represents positive and 5 represents negative.
E.g.: Check result
05199520
+ 04967850
05199520 = 0.99520 x 101 = 9.520
04967850 = 0.67850 x 10-1 = 0.067850 + 10.019850
In sign-magnitude form = 0.1001985 x 102
58
2.6 Floating-point number representation & standard
2.6.3 Floating Point Representations
Floating Point Representation - SEEMMMMM
❑ Multiply and divide
Mantissa: Multiplied or divided
Exponent: Added or subtracted and adjusted excess value since added trice
Assume that:
Excess-50 is applied.
A 0 represents positive and 5 represents negative.
E.g.:
Assume that two number with exponent 3, each representing 53.
Adding the two exponent: 53 + 53 = 106
Since 50 (excess-50) is added twice, subtract: 106 – 50 = 56
Normalization necessary to:
Restore location of decimal point
Maintain precision of the result.
59
2.6 Floating-point number representation & standard
2.6.3 Floating Point Representations
Floating Point Representation - SEEMMMMM
❑ Multiply and divide
Assume that:
Excess-50 is applied.
A 0 represents positive and 5 represents negative.
E.g.: multiply two floating pint numbers
05220000
x 04712500
Add exponent, subtract offset = 75 + 47 – 50 = 49
Multiply mantissa = 0.20000 x 0.12500
= 0.025000000
Normalized the result = 04825000
60
2.6 Floating-point number representation & standard
Assume that:
Excess-50 is applied.
A 0 represents positive and 5 represents negative.
62
2.6 Floating-point number representation & standard
2.6.3 Floating Point Representations
▪ Floating Point Representation – IEEE754
❑ E.g.: Convert 253.7510 to binary floating point form.
253. 7510
= 1111 1101. 112
Therefore, 253.1110 = 1111 1101.112
= 1.111 110111 x 2+7
0 10000110 11111011100..
63
2.7 Bitwise Logical Operations
E.g.: OR
1 1 0 0
OR 1 0 1 0
1 1 1 0
65
2.7 Bitwise Logical Operations
NOT 1 0
0 1
E.g.: XOR
1 1 0 0
XOR 1 0 1 0
0 1 1 0
66
Chapter 2: Digital Logic & Numerical Data Representation
Self-Review
-EBCOIC
-ASCII
2.1 Alphanumeric character data representation 2.5 Signed and unsigned number representation
-Conversion
2.2 Numbering Systems -Competion 2.5.1 Integer Representation
2.2.1 Decimal numbers 2.5.2 Sign-and-magnitude Representation
2.2.2 Binary Numbers 2.5.3 Two's complement