0% found this document useful (0 votes)
11 views61 pages

Chapter 2 Computer Architecture and Orgnization

This document covers Chapter 2 of a Computer Organization and Architecture course, focusing on number systems and codes. It explains various number systems (decimal, binary, octal, hexadecimal), their conversions, and data representation techniques including fixed-point and floating-point representations. Additionally, it discusses data types, complements, and basic arithmetic operations in binary, providing examples and exercises for better understanding.

Uploaded by

yesusgooftadha6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views61 pages

Chapter 2 Computer Architecture and Orgnization

This document covers Chapter 2 of a Computer Organization and Architecture course, focusing on number systems and codes. It explains various number systems (decimal, binary, octal, hexadecimal), their conversions, and data representation techniques including fixed-point and floating-point representations. Additionally, it discusses data types, complements, and basic arithmetic operations in binary, providing examples and exercises for better understanding.

Uploaded by

yesusgooftadha6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 61

College Of Natural Science

Department Computer Science


Course Tile:- Computer organization and Architecture
(COA)
Chapter 2
Number Systems and Codes
Instructor:- Zerihun T.
E-mail:- [email protected]

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

Don’t use a calculator!


Answer
Hexa-
Decimal Binary Octal decimal
33 100001 41 21
117 1110101 165 75
15
Arithmetic operations
Basic arithmetic operations include addition, subtraction, multiplication and
division .
Basic Rules of Addition:

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)

Add the Binary numbers 11010 and 1100 1 1


1 1 0 1 0
+ 1 1 0 0
1 0 0 1 1 0
Exercise
a)11+11
17
Binary Subtraction Rules
 The rules for binary subtraction are quite straightforward except that
when 1 is subtracted from 0, a borrow must be created from the next
most significant column.
 This borrow is then worth 210 or 102 because a 1 bit in the next
column to the left is always worth twice the value of the column on its
right.

Always Borrows to 2 because it is base 2 18


Example: Subtract binary number 101 from 1011
(borrow
)
02
1 0 1 1
- 1 0
1
0 1 1 0
0 10 1 0
Subtract binary number 11 from 1010 2
1 0 1 0
Exercise - 1 1
1: 0011010 – 001100
Answer 0 1 1 1
0001110
2: 0100010 – 0001010
Answer
001100011 19
Data Type
When we type some letters or words, the computer translates them in
numbers as computers can understand only numbers.
A computer can understand the positional number system where there are
only a few symbols called digits and these symbols represent different
values depending on the position they occupy in the number.
Data refers to the symbols that represent people, events, things, and ideas.
Data Representation refers to the form in which data is stored, processed, and
transmitted.
Devices such as smartphones, iPods, and computers store data in digital
formats that can be handled by electronic circuitry.
Digitization is the process of converting information, such as text, numbers,
photo, or music, into digital data that can be manipulated by electronic
devices.
20
Bit, bytes and words
Bit- Bit is the smallest unit of data that can be stored in a computer.
word It is a single bit that can be stored in a computer.
 In other s, it is a single bit that can represent two values; either 0 or 1.
Byte- Without question, the most important data structure used by the most
microprocessor is the byte.
A byte consists of eight bits and is the smallest addressable datum (data item)
in the microprocessor.
 It is the most important data structure & is used by most microcomputer.
Word- A word is a group of bits greater than or equal to 8 bits.
There is no fixed size for a word length.
It depends on from computer to computer.
Most microprocessors & minicomputers are normally byte oriented with
word length 8 bits, 16 bits 32 bits & 64 bits. 21
Complements
 Complement are used in digital computer for
simplifying the subtraction operation and for logical
manipulation.
There are two types of complement for each base
system the r’s and (r-1)’ complement.
Complements

r‘s complement (r-1)‘s complement


(Radix Complement) (Diminished Radix Complement)
22
r‘s complements
Example:- Complements of ( 7) is 10-7=3, Complements of (9 ) is 10-9=1
Formula Derived
-N is r’s Complements
Where r ix base,
n the number of digit ,
N is the give number

Example1. N=5690 determine 10’s complements


Given r=10
N=5690
n=4
Soliton
23
Example1. N=1101 determine 2’s complements
N=1101
r=2
n=4 Binary Number
Solution
-1101=(-1101
16 changed to be Binary
=10000-1101
=11 Borrow 2 =
2
10000
-1101
00011

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

Unsigned Singed 1’s complement 2’s Complement

 Negative numbers must be represented by signed


numbers since + and – signs are not available, only
1’s and 0’s are
27
Data Representation
Signed represent positive binary number
Unsigned represent positive and negative binary number
1’s Complement represent positive and negative Binary number
2’s Complement represent positive and negative Binary number
In 4 representations positive number represented is the same way
Unsigned Representation
Example
+6=110
-6= can’t represent 28
Data Representation
If Sign bit is zero, it implies the number is positive
If Sign bit is 1 , it implies the number is negative
Example
+6= 0 Magnitude Number
110

Signed bit msb


-6= 1
110

29
Data Representation
Signed-magnitude representation
Example 2:-
+13= 01101
-13= 11101

 Signed numbers have msb as 0 for positive and 1 for negative –


msb is the sign bit
 Two ways to designate binary point position in a register
1. Fixed point position
2. Floating-point representation

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.

An input device stores an unsigned integer using the following steps:

1. The integer is changed to binary.


2. If the number of bits is less than n, 0s are added to the left.

32
Example 1

Store 7 in an 8-bit memory location using unsigned representation.


Solution
First change the integer to binary, (111)2. Add five 0s to make a total of eight bits,
(00000111)2. The integer is stored in the memory location. Note that the
subscript 2 is used to emphasize that the integer is binary, but the subscript is not
stored in the computer.
Example 2
Store 258 in a 16-bit memory location.

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

represents positive integers, the second half, negative integers.

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

Store +28 in an 8-bit memory location using sign-and-magnitude representation.

Solution
The integer is changed to 7-bit binary. The leftmost bit is set to 0. The 8-
bit number is stored.

Example 2

Store -28 in an 8-bit memory location using sign-and-magnitude representation.


Solution
The integer is changed to 7-bit binary. The leftmost bit is set to 1. The 8-bit number is stored.

37
Example 3

Retrieve the integer that is stored as 01001101 in sign-and-magnitude representation.


Solution
Since the leftmost bit is 0, the sign is positive. The rest of the bits (1001101) are changed to
decimal as 77. After adding the sign, the integer is +77.

Example 4

Retrieve the integer that is stored as 10100001 in sign-and-magnitude representation.

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-

bit is changed to a 1-bit, a 1-bit is changed to a 0-bit.

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.

If it is 0, the integer is positive. If it is 1, the integer is negative.

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

Signed-2’s complement representation


Example:- fined +6 and -6 2’s Complement
First we find first complement
+6=01101
-6=10010
44
Floating-point representation

The solution for maintaining accuracy or precision is to use floating-point representation.

The three parts of a real number in floating-point representation

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

The following shows the decimal number

7,452,000,000,000,000,000,000.00

in scientific notation (floating-point representation).

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

Show the number


−0.0000000000000232
in scientific notation (floating-point representation).

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

Show the number


(101001000000000000000000000000000.00)2
in floating-point representation.

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

 709310 = ? (in BCD)

7 0 9 3

0111 0000 1001 0011

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

000 001 010 011 100 101 110 111


0000 NULL DLE 0 @ P ` p
0001 SOH DC1 ! 1 A Q a q
0010 STX DC2 " 2 B R b r
0011 ETX DC3 Most
# significant
3 C S c s
0100 EDT DC4 $ bit 4 D T d t
0101 ENQ NAK % 5 E U e u
0110 ACK SYN & 6 F V f v
0111 BEL ETB ' 7 G W g w
1000 BS CAN ( 8 H X h x
1001 HT EM ) 9 I Y i y
1010 LF SUB * : J Z j z
Least significant
1011 VT ESC + ; K [ k {
1100 bit
FF FS , < L \ l |
1101 CR GS - = M ] m }
1110 SO RS . > N ^ n ~
1111 SI US / ? O _ o DEL
52
ASCII Table
e.g., ‘a’ =
1100001
000 001 010 011 100 101 110 111
0000 NULL DLE 0 @ P ` p
0001 SOH DC1 ! 1 A Q a q
0010 STX DC2 " 2 B R b r
0011 ETX DC3 # 3 C S c s
0100 EDT DC4 $ 4 D T d t
0101 ENQ NAK % 5 E U e u
0110 ACK SYN & 6 F V f v
0111 BEL ETB ' 7 G W g w
1000 BS CAN ( 8 H X h x
1001 HT EM ) 9 I Y i y
1010 LF SUB * : J Z j z
1011 VT ESC + ; K [ k {
1100 FF FS , < L \ l |
1101 CR GS - = M ] m }
1110 SO RS . > N ^ n ~
1111 SI US / ? O _ o DEL53
ASCII Table
95 Printing
codes
000 001 010 011 100 101 110 111
0000 NULL DLE 0 @ P ` p
0001 SOH DC1 ! 1 A Q a q
0010 STX DC2 " 2 B R b r
0011 ETX DC3 # 3 C S c s
0100 EDT DC4 $ 4 D T d t
0101 ENQ NAK % 5 E U e u
0110 ACK SYN & 6 F V f v
0111 BEL ETB ' 7 G W g w
1000 BS CAN ( 8 H X h x
1001 HT EM ) 9 I Y i y
1010 LF SUB * : J Z j z
1011 VT ESC + ; K [ k {
1100 FF FS , < L \ l |
1101 CR GS - = M ] m }
1110 SO RS . > N ^ n ~
1111 SI US / ? O _ o DEL
54
ASCII Table
Alphabetic
codes
000 001 010 011 100 101 110 111
0000 NULL DLE 0 @ P ` p
0001 SOH DC1 ! 1 A Q a q
0010 STX DC2 " 2 B R b r
0011 ETX DC3 # 3 C S c s
0100 EDT DC4 $ 4 D T d t
0101 ENQ NAK % 5 E U e u
0110 ACK SYN & 6 F V f v
0111 BEL ETB ' 7 G W g w
1000 BS CAN ( 8 H X h x
1001 HT EM ) 9 I Y i y
1010 LF SUB * : J Z j z
1011 VT ESC + ; K [ k {
1100 FF FS , < L \ l |
1101 CR GS - = M ] m }
1110 SO RS . > N ^ n ~
1111 SI US / ? O _ o DEL
55
ASCII Table
Numeric
codes
000 001 010 011 100 101 110 111
0000 NULL DLE 0 @ P ` p
0001 SOH DC1 ! 1 A Q a q
0010 STX DC2 " 2 B R b r
0011 ETX DC3 # 3 C S c s
0100 EDT DC4 $ 4 D T d t
0101 ENQ NAK % 5 E U e u
0110 ACK SYN & 6 F V f v
0111 BEL ETB ' 7 G W g w
1000 BS CAN ( 8 H X h x
1001 HT EM ) 9 I Y i y
1010 LF SUB * : J Z j z
1011 VT ESC + ; K [ k {
1100 FF FS , < L \ l |
1101 CR GS - = M ] m }
1110 SO RS . > N ^ n ~
1111 SI US / ? O _ o DEL
56
ASCII Table
Punctuation,
etc.
000 001 010 011 100 101 110 111
0000 NULL DLE 0 @ P ` p
0001 SOH DC1 ! 1 A Q a q
0010 STX DC2 " 2 B R b r
0011 ETX DC3 # 3 C S c s
0100 EDT DC4 $ 4 D T d t
0101 ENQ NAK % 5 E U e u
0110 ACK SYN & 6 F V f v
0111 BEL ETB ' 7 G W g w
1000 BS CAN ( 8 H X h x
1001 HT EM ) 9 I Y i y
1010 LF SUB * : J Z j z
1011 VT ESC + ; K [ k {
1100 FF FS , < L \ l |
1101 CR GS - = M ] m }
1110 SO RS . > N ^ n ~
1111 SI US / ? O _ o DEL
57
Example: “Hello, world”

Binary Hexadecimal Decimal


H = 1001000 = 48 = 72
e = 1100101 = 65 = 101
l = 1101100 = 6C = 108
l = 1101100 = 6C = 108
o = 1101111 = 6F = 111
, = 0101100 = 2C = 44
= 0100000 = 20 = 32
w = 1110111 = 77 = 119
o = 1100111 = 67 = 103
r = 1110010 = 72 = 114
l = 1101100 = 6C = 108
d = 1100100 = 64 = 100
58
ASCII vs Unicode
-Both are character codes
-The 128 first code positions of Unicode mean the
same as ASCII

-Has 128 code points, 0 -Has about 1,114,112 code


through 127 positions
-Can only encode characters -Can encode characters in
in 7 bits 16-bits and more
-Can only encode characters -Can encode characters
from the English language from virtually all kinds of
languages
-It is a superset of ASCII

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

You might also like