Chapter 2 Computer Architecture and Orgnization
Chapter 2 Computer Architecture and Orgnization
1
Data Presentation
Chapter objectives:- After Completing this Chapter you Will be able to
grasp The following concepts:
Number System
Data Types
Complements
Fixed-Point Representation
Floating-Point Representation
Codes 2
Number Systems
3
Common Number Systems
Used by Used in
System Base Symbols humans? computers?
Decimal 10 0, 1, … 9 Yes No
Binary 2= 0, 1 No Yes
Octal 8= 0, 1, … 7 No No
Hexa- 16= 0, 1, … No No
decimal 9,
A, B, …
F
4
Quantities/Counting (1 of 15)
Hexa- Hexa-
Decimal Binary Octal decimal Decimal Binary Octal decimal
0 0 0 0 8 1000 8
1 1 1 1 9 1001 9
2 10 2 2 10 1010 A
3 11 3 3 11 1011 B
4 100 4 4 12 1100 C
5 101 5 5 13 1101 D
6 110 6 6 14 1110 E
7 111 7 7 15 1111 F
5
Questions
6
Conversion Among Bases
• The possibilities:
Decimal Octal
Binary Hexadecimal
7
Example
2510 = 110012 = 318 = 1916 Weight
Decimal Representation
12510 => 5 x 100 = 5
2 x 101 = 20
1 x 102 = 100
Base 125
Binary
1.Binary to Decimal
2.Otal to Decimal Octal Decimal
3.Hexadecimal to Decimal
Hexadecimal 8
1.Binary to Decimal Decimal Binary
Technique
Multiply each bit by 2n, where n is the “weight” of the bit
The weight is the position of the bit, starting from 0 on the right
Add the results
Example
1010112 => 1 x 20 = 1
1 x 21 = 2
0 x 22 = 0
1 x 23 = 8
0 x 24 = 0
1 x 25 = 32
4310
9
2.Octal to Decimal Decimal Octal
Technique
Multiply each bit by 8n, where n is the “weight” of the bit
The weight is the position of the bit, starting from 0 on the right
Add the results
Examp
le 724 => 8 4 x 80 = 4
2 x 81 = 16
7 x 82 = 448
46810
10
3.Hexadecimal to Decimal Decimal Hexadecimal
Technique
Multiply each bit by 16n, where n is the “weight” of the bit
The weight is the position of the bit, starting from 0 on the right
Add the results
Exampl
e ABC 16 => C x 160 = 12 x 1 = 12
B x 161 = 11 x 16 = 176
A x 162 = 10 x 256 = 2560
274810
11
4. Decimal to Binary
5.Otal to Binary
6.Hexadecimal to Binary
Decimal
Binary
Octal
Hexadecimal
12
4.Decimal to Binary Decimal Binary
Technique
Divide by two, keep track of the remainder
First remainder is bit 0 (LSB, least-significant bit)
Second remainder is bit 1
Etc.
Example 12510 = ?2 125 2
124 62 2
1 62 31 2
0 30 15 2
1 14 7 2
1 6 3 2
1 2 1
12510 = 11111012 1
13
Decim Bina Oct Hexa
al ry al
Technique
5.Octal to Binary
0 0 0 0
1 1 1 1
Convert each octal digit to a 3-bit
2 10 2 2 equivalent binary representation
Exampl
3 11 3 3
7 0 5
4 100 4 4
5
6
101
110
5
6
5
6
e 705 = ? 8 2 111 000 101
7 111 7 7
8 1000 8 7058 = 1110001012
9 1001 9 6.Hexadecimal to Binary
10 1010 A Technique:- Convert each hexadecimal digit to a 4-
11 1011 B bit equivalent binary representation
12 1100 C 1 0 A F 10AF16 = ?2
13 1101 D
14 1110 E 0001 0000 1010 1111
15 1111 F 10AF16 = 00010000101011112 14
Exercise – Convert ...
Hexa-
Decimal Binary Octal decimal
33
1110101
1. Binary Addition:
the basic rules of binary addition as follows:
1. 0 + 0 = 0.
2. 0 + 1 = 1.
3. 1 + 0 = 1.
4. 1 + 1 = 0 with a carry of ‘1’ to the next more significant bit.
5. 1 + 1 + 1 = 1 with a carry of ‘1’ to the next more significant bit.
16
•Example1: Add the binary numbers 1010 and 11
(carry)
1
1 0 1 0
+ 1 1
1 1 0 1 (carry)(carry)
Check 16-13=3 24
(r-1)‘s complement
Formula r’s complment
-N is r’s Complement
Therefore;
Where r ix base,
(r-1’s) Complement=(
n the number of digit ,
N is the give number
r‘s complement
complements
=r‘s complement - 1
(r-1’s) Complement+1=r‘s complement
r‘s complement=(r-1’s) Complement+1
1. Binary Number Complement
In binary number system we have the 1’s and 2’s complement the 1’s is obtained by replacing 0s with 1s and 1s with 0s.
2’s complement = 1’s complement +1.
Example : Find the 1’s and 2’s complement of the following number : 1011000.
25
Solution :1’s comp.=0100111 ;2’s =0100111+1=0101000
r‘s complement=(r-1’s)
2. Decimal Number Complement
Complement+1
In decimal number system we have the 9’s and 10’s complement the 9’s is obtained by subtracting each digit from 9
10’s complement = 9’s complement +1.
Example : Find the 9’s and 10’s complement of the following number :2496.
Solution :
9’s comp.= 9999-2496 = 7503;10’s =7503+1=7504
3. Octal Number Complement:
In octal number system we have the 7’s and 8’s complement the 7’s is obtained by subtracting each digit from 7
8’s complement = 7’s complement +1.
Example : Find the 7’s and 8’s complement of the following number :562.
Solution :
7’s comp.= 777- 562 = 215;8’s =215+1=216
Hexadecimal Number Complement:
In hexadecimal number system we have the 15’s and 16’s complement the 15’s is obtained by subtracting each digit from 15
16’s complement = 15’s complement +1.
Example : Find the 15’s and 16’s complement of the following number :3BF.
Solution :
15’s comp.= 15 15 15 – 3 B F = C 4 0;16’s =C 4 0+1=C 4 1
26
Data Representation
Data Representation
Magnitude Complement
29
Data Representation
Signed-magnitude representation
Example 2:-
+13= 01101
-13= 11101
30
Fixed Point Representation
An integer is normally stored in memory using fixed-point representation.
When an integer is positive, the msb, or sign bit, is 0 and the remaining bits
represent the magnitude
When an integer is negative, the msb, or sign bit, is 1, but the rest of the
number can be represented in one of three ways
o Signed-magnitude representation
o Signed-1’s complement representation
o Signed-2’s complement representation
31
Unsigned representation
An unsigned integer is an integer that can never be negative and can take only 0 or positive values.
32
Example 1
258 2
258 129 2
0 128 64 2
1 64 32 2
0 32 16 2
0 16 2
0 8
8 4 2
0 4 2 2
0 2 1
Solution
First change the integer to binary (100000010)2. Add seven00s to make a total of sixteen bits,
(0000000100000010)2. The integer is stored in the memory location.
34
Example 3
What is returned from an output device when it retrieves the bit string
00101011 stored in memory as an unsigned integer?
Solution
Using the procedure shown in previous lecture , the binary integer is
converted to the unsigned integer 43.
35
Sign-and-magnitude representation
n
In this method, the available range for unsigned integers (0 to 2 − 1) is divided into two equal sub-ranges. The first half
In sign-and-magnitude representation, the leftmost bit defines the sign of the integer. If it is 0, the integer is positive. If it is 1, the
integer is negative.
36
Example 1
Solution
The integer is changed to 7-bit binary. The leftmost bit is set to 0. The 8-
bit number is stored.
Example 2
37
Example 3
Example 4
Solution
Since the leftmost bit is 1, the sign is negative. The rest of the bits (0100001) are changed to
decimal as 33. After adding the sign, the integer is −33.
38
One’s Complementing
Before we discuss this representation further, we need to introduce two operations. The first is called one’s complementing or taking the one’s
complement of an integer. The operation can be applied to any integer, positive or negative. This operation simply reverses (flips) each bit. A 0-
Example 1 The following shows how we take the one’s complement of the integer 00110110.
Example 3.9
The following shows that we get the original integer if we apply the one’s complement
operations twice.
39
Two’s complement representation
Almost all computers use two’s complement representation to store a signed integer in an n-bit memory location.
The second operation is called two’s complementing or taking the two’s complement of an integer in binary. This operation is done in two
steps.
First, we copy bits from the right until a 1 is copied; then, we flip the rest of the bits.
Example 1
The following shows how we take the two’s complement of the integer 00110100.
40
Example 2
The following shows that we always get the original integer if we apply the two’s complement
operation twice.
In two’s complement representation, the leftmost bit defines the sign of the integer.
An alternative way to take the two’s complement of an integer is to first take the one’s complement and then add 1 to the result.
41
Comparison
Exercise
1. Consider an 8-bit register and the number +14unsined
2. Consider an 8-bit register and the number –14
A. Signed magnitude:
B. Signed 1’s complement:
C. Signed 2’s complement:
3. Fined +6 and -6 2’s Complement
43
Signed-1’s complement representation
In 4 representations positive number represented is the same way
Example:-
First we find +6 complement
+6=01101
-6=10010
A floating point representation of a number is made up of three parts: a sign, a shifter and a fixed-point number.
Floating-point representation is used in science to represent very small or very large decimal numbers. In this representation called scientific notation, the
fixed-point section has only one digit to the left of point and the shifter is the power of 10.
45
Example 1
7,452,000,000,000,000,000,000.00
The three sections are the sign (+), the shifter (21) and the fixed-point part (7.425). Note that
the shifter is the exponent.
Some programing languages and calculators shows the number as +7.425E21
Example 2
Solution
We use the same approach as in the previous example—we move the decimal point after the
digit 2, as shown below:
The three sections are the sign (-), the shifter (-14) and the fixed-point part (2.32). Note that
the shifter is the exponent.
Example 3
Solution
We use the same idea, keeping only one digit to the left of the decimal point.
Codes
Computer code helps us to represent characters
in a coded form in the memory of the computer.
These codes represent specific formats which
are used to record data
Some of the commonly used computer codes are:
BCD
ASCII
Unicode
49
BCD: Example
7 0 9 3
50
ASCII Features
• Developed by ANSI (American National Standards Institute)
• 7-bit code
• 8th bit is unused (or used for a parity bit or to indicate “extended” character set)
• 27 = 128 different codes
• Two general types of codes:
95 are “Printing” codes (displayable on a console)
33 are “Control” codes (control features of the console or communications
channel)
• Represents
Latin alphabet, Arabic numerals, standard punctuation characters
Plus small set of accents and other European special characters (Latin-I ASCII)
51
ASCII Table
59
ASCII vs Unicode
The main difference between ASCII and Unicode is that the ASCII
represents lowercase letters (a-z), uppercase letters (A-Z), digits
(0-9) and symbols such as punctuation marks while the Unicode
represents letters of English, Arabic, Greek etc., mathematical symbols,
historical scripts, and emoji covering a wide range ..
60
Questions
61