0% found this document useful (0 votes)
98 views53 pages

Topic 2 - Subtopic 2.1

This chapter discusses data representation and arithmetic operations in different number systems including decimal, binary, octal, hexadecimal and binary-coded decimal. It explains how to convert between these number systems and perform basic arithmetic like addition and subtraction. Additionally, it covers various coding systems for representing positive and negative numbers like sign-magnitude, one's complement and two's complement coding.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
98 views53 pages

Topic 2 - Subtopic 2.1

This chapter discusses data representation and arithmetic operations in different number systems including decimal, binary, octal, hexadecimal and binary-coded decimal. It explains how to convert between these number systems and perform basic arithmetic like addition and subtraction. Additionally, it covers various coding systems for representing positive and negative numbers like sign-magnitude, one's complement and two's complement coding.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 53

Chapter 2:

Arithmetic And Logic


CLO1 : Explain computer function in central
processing unit, arithmetic, logic and assembly
language in computer system
( C2 , PLO 1 )
2.1 Explain the conversion data representation on Central
Processing Unit (CPU).
2.1.1 Define decimal, binary, octal and hexadecimal number.

2.1.2 Explain arithmetic operation (addition and subtraction) in


different number bases.

2.1.3 Convert decimal, binary, octal and hexadecimal numbers to


different bases and vice-versa.

2.1.4 Explain the coding system:


a. Sign and magnitude
b. 1’s Complement and 2’s Complement
c. Binary Coded Decimal (BCD system)
d. ASCII code
INTRODUCTION
• The binary system and decimal system is most important in
digital system.
• Decimal - Universally used to represent quantities outside a
digital system.
• Its means, there will be situations decimal values must be
converted to binary values before entered to digital system.
• Example : Calculator / Computer
DECIMAL NUMBERING SYSTEM
(10 DIGIT)
• Decimal system is composed of 10 numerals or sysmbols.

 These 10 sysmbols are 0, 1, 2, 3, 4, 5, 6,


7, 8, 9.
 Using these symbols as digits of a
number, it can express any quantity.
• Base number = 10
• Basic number = 0,1,2,3,4,5,6,7,8,9

Basic number

23410 Base number


• ADDITION DECIMAL NUMBERS

Example: 45710 + 24510


L3 L2 L1
L1 = 7 + 5 =12 – 10 = 2
L2 = 5 + 4 = 9 + 1 -10 = 0
4 5 710
L3 = 4 + 2 = 6 + 1 = 7
+ 2 4 510
7 0 210
• SUBSTRACTION DECIMAL NUMBERS
Example: 45710 + 24510
L3 L2 L1

4 5 710
- 2 6 510 L1 = 7 - 5 = 2
1 9 210 L2 = 5 +10 – 6 =9
L3 = 3 – 2 = 1
BINARY NUMBERING SYSTEM
(2 DIGIT)
• Define Binary numbers
• Binary numbers representing number in which only
digits 0 or 1.
• ADDITION BINARY NUMBERS
Basic binary addition rule :
0+0=0
0+1=1
1+0=1
1 + 1 = 10
• Example : 101 + 101 = 1010
1011 + 1011 = ?
Exercise
• Ex 1:
110112 + 100012 = 1011002

• Ex 2:
• 101112 + 1112 = ________
Subtraction
Four conditions in binary subtraction
• 0-0=0
• 0 - 1 = 1 borrow 1
• 1-0=1
• 1-1=0
Exercise
• Ex 1:
10012 – 102 = 1112

• Ex 2:
• 1010112 – 11112 =__________
OCTAL NUMBERING SYSTEM
( 8 DIGIT )
• The octal number system has a base of eight, meaning that it has eight
possible digits: 0,1,2,3,4,5,6 and 7.
• The digit positions in an octal number have weights as follows :

84 83 82 81 80 8-1 8-2 8-3


Octal number - Addition
 Ex:
• Ex:
1238
4578
+ 3218 + 2458
4448
Octal number - (Subtraction)
• Ex:
5248 – 1678 = 3358

1678 – 248 = _________


HEXADECIMAL NUMBERING SYSTEM
( 16 DIGIT )
• The hexadecimal number system uses base 16.
• It has 16 possible digit symbols.
• It uses the digits 0 through 9 plus the letters A, B, C, D, E and F as the
16 digit symbols.

Basic number

7A16 Base number


Hexadecimal number - Addition

• Ex:
 Ex:
3 316 2 0 D 316
• + 4 716 + 1 2 B C16
7 A16
Hexadecimal number - Subtraction
 Ex:  Ex:
4 416 3 2 5 516
- 1 716 - 3 1 8 216
2 D16
FORMULA CONVERTING BETWEEN
NUMBER BASES
a)2 to10 : a x 2n + b x 2n-1 + c x 2n-2 + …….
10 to 2: base 10 divide 2
b) 2 to 8: 001
 100
 101

1 4 5
8 to 2: 4 5
100 101
c) 2 to 16 : 1110 1001
 
14 9
16 to 2:  3 A
0011 1010
d) 10 to 8 : base 10 divide 8
8 to10 : a x 8n + b x 8n-1 + c x 8n-2 + …….
e) 10 to 16 : base 10 divide 16
16 to 10 : a x 16n + b x 16n-1 + c x 16n-2 +…..
f) 8 to 16 : either 8 to 10 to 16 or 8 to 2 to 16
16 to 8 : 16 to 2 to 8 or 16 to 10 to 8
Conversions Between Base Number
Binary (2) to Decimal (10) conversions
• Example : 1 1 0 1 12
• 24 + 23 + 22 + 21 + 20 = 16 + 8 + 2 + 1
= 2710
Decimal (10) to Binary (2) conversions

• Convert 25 to binary number


10

Exercise: Convert 30 to binary number


10
Octal (8) –to-decimal(10) conversion

Convert 3788 to decimal number

3788 = 3 x (82) + 7 x (81) + 2 x (80)


= (3 x 64) + (7x 8) + (2 x 1)
= 25010
Decimal(10)-to-Octal(8) Conversion

• Decimal integer can be converted to octal by


using the same repeated-division method with a
division factor of 8.
Octal(8) –to- Binary (2) conversion
Binary(2) to Octal (8)conversion
Hexadecimal(16)-To-Decimal(10)
Conversion
• A hexadecimal number can be converted to its decimal equivalent
by using the fact that each hex digit position has a weight that is a
power of 16.
• Ex 1:
1416 = (1 x 161) + (4 x 160)
= 16 + 4
= 2010
• Ex 2:
ABC16 = (10 x 162) + (11 x 161)
= (12 x 160)
= 2560 + 176 + 12
= 274810
Decimal(10)-To-Hexadecimal(16)
Conversion
• Decimal to hex conversion can be done using repeated division by 16.
• Ex: Convert 2010 to hex

16 20
16 1 4

2010 = 1416
Hexadecimal (16)-to-Binary(2) Conversion

• Like the octal number system, the hexadecimal number system is used
primarily as a “shorthand” method for representing binary numbers.
• It is a relatively simple matter to convert a hex number to binary .
• Each hex digit is converted to its four-bit binary equivalent.
• Ex:
111010012 = __________

00101101001111002 =___________
Binary(2)-to-Hexadecimal(16) Conversion

• The binary number is grouped into groups of four bits, and each
group is converted to its equivalent hex digit.
• Zero are added, as needed to complete a four-bit group.
• Ex:
1012 = 0101
= 516
Summary
Hexadecimal Decimal Binary
0 0 0000
1 1 0001
2 2 0010
3 3 0011
4 4 0100
5 5 0101
6 6 0110
7 7 0111
Summary
Hexadecimal Decimal Binary
8 8 1000
9 9 1001
A 10 1010
B 11 1011
C 12 1100
D 13 1101
E 14 1110
F 15 1111
2.1.4 Describe the coding system

a. Sign and magnitude


b. 1’s Complement and 2’s
Complement
c. Binary Coded Decimal (BCD system)
d. ASCII
a. Sign and Magnitude
• In an 8 bit word, signed magnitude representation places the
absolute value of the number in the 7 bits to the right of the
sign bit,
• For example in 8 bit sign magnitude,positive 3 is : 0000 0011
• Negative 3 is: 1000 0011
b. One’s Complements and Two’s
Complements
• One’s Complements
• One’s complements is used in binary number.
• The one’s complement of a binary number is obtained by changing each 0 to 1
and 1 to a 0.
• Only change negative number
• In other words, change each bit in the number to its complement.
• Exp:

• 10011001 – original binary number

• 01100110 – complement each bit to


form 1’s complement
• Thus, we say that the 1’s complement of 10011001 is
01100110.
• Exp:

• Convert -2710 to 1’s complement


a) 2710 = 110112
b) 110112 = 001002

• Convert -4510 to 1’s complement


-------------
• Two’s Complement
• The 2’s complement of a binary number is formed by taking the 1’s complement
of the number and adding 1 to the least-significant-bit (LSB) position.
• Exp:
101101 binary equivalent of 45
010010 complement each bit to form
1’s complement
+ 1 add 1
010011 2’s complement of original binary
number

Two’s complement = One’s Complement + 1


Exercise

1. Convert the number below to 1’s complement


and 2’s complement.
i. -101110012
ii. -5768
iii. -124516
iv. -4510
c. BCD Code
• BCD – Binary Coded Decimal

• It’s contain BCD 8421, 2421, 3321, 5421, 5311, 4221


and etc.

• The common used is BCD 8421 and BCD 2421.


4 bit BCD Code
Desimal 5421 5311 4221 3321 2421 8421 7421

0 0000 0000 0000 0000 0000 0000 0000

1 0001 0001 0001 0001 0001 0001 0001

2 0010 0011 0010 0010 0010 0010 0010

3 0011 0100 0011 0011 0011 0011 0011

4 0100 0101 1000 0101 0100 0100 0100

5 1000 1000 0111 1010 1011 0101 0101

6 1001 1001 1100 1100 1100 0110 0110

7 1010 1011 1101 1101 1101 0111 1000

8 1011 1100 1110 1110 1110 1000 1001

9 1100 1101 1111 1111 1111 1001 1010


Binary-Coded-Decimal Code

• If each digit of a decimal number is represented by its


binary equivalent, the result is a code called binary-coded-
decimal.

• Decimal digit can be as large as 9, four bits are required to


code each digit (the binary code for 9 is 1001)
• Exp: 87410

8 7 4 (decimal)

1000 0111 0100 (BCD)


BCD 8421 Code – to – Binary Number
• Exp:
Convert 1001 0110BCD 8421 to binary number.
Step 1: Change BCD 8421 code to decimal number
1001 0110

9 6

Step 2 : Change decimal number to binary number

1001 0110BCD 8421 = 11000002


Binary Number – to – BCD 8421
Code
• Exp:
Convert 10010102 to BCD 8421 code.
Step 1: Change binary number to decimal
number.
10010102 = 7410

Step 2: Change decimal number to BCD


8421 code.
10010102 = 01110100BCD 8421
d. ASCII Code
• The most widely used alphanumeric code is the
American Standard Code for Information Interchange
(ASCII).

• The ASCII code is a seven-bit code and so it has 27


= 128 possible code groups.
• ASCII code is used to represent data internally in
personal computers.
ASCII
code
• Exp:
An operator is typing in a BASIC program at the keyboard of
a certain microcomputer. The computer convert seach
keystroke into its ASCII code and stores the code as a byte
in memory. Determine the binary strings that will be
entered into memory when operator types in the following
BASIC statement:

CSA 10093
Exercise :

1.The following message encode in ASCII code. What the meaning of this
code ?

• a) 54 4F 4C 4F 45 47
• b) 48 45 4C 4C 4F
• c) 41 50 41 4B 48 41 42 41 52
How the character sent from the keyboard
to the computer?
• Step 1: The user presses the letter T key on
the keyboard.
• Step 2: An electronic signed the letter T and
sent to system unit.
• Step 3: The signed for letter T is converted to
its ASCII code and stored in memory
for processing.
• Step 4: The binary code for the letter T is
converted to an image on the output
device.

You might also like