You are on page 1of 13

CSC242 Computer Architecture Summer 2011 Lecture 02: Arithmetic Review

Affaq Qamar affaq@iqraisb.edu.pk


[Adapted from Computer Organization and Design, Patterson & Hennessy, 3rd Edition]

CSC242 L02 Arithmetic Review

Number System
Binary (Base 2)
Best for computers Only 1s and 0s Example: 1011, 00, 10, 110001, 0000110

Decimal (Base 10)


Humans prefer Starts from 0 and goes till 9 Example: 12, 0, 22323354679, 90000,10,1

Hexadecimal (Base 16)


Suits both humans and computers Starts from 0 and goes till F Example: 12, 4, 1A, BC, FFFF, 25E

CSC242 L02 Arithmetic Review

Conversion
Binary-to-Decimal
1 23 1 22 0 21 1 20

(1101)2 = (1x23 + 1x22 + 0x21 + 1x20)10 (1101)2 = (13)10

Decimal-to-Binary
(13)10 = (?)2

CSC242 L02 Arithmetic Review

Conversion
Binary-to-Hexadecimal
(10001100)2 = (?)16

Hexadecimal 0 1 2 3 4 5 6 7 8 9 A B C D E F

Binary 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111

Decimal 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
4

Hexadecimal-to-Binary
(9AF)16 = (?)2

CSC242 L02 Arithmetic Review

Other Number Systems


Octal (Base 8) Binary-coded-decimal (BCD) ASCII Code (American Standard Code for Information Interchange)

CSC242 L02 Arithmetic Review

Examples
Convert the following to:
Decimal: 11001001, 11110 Binary: (100)10, (67)10, (100)16, (67)16, CD42 Hexadecimal: 111010001000101111010110

CSC242 L02 Arithmetic Review

Signed and Unsigned Numbers


The conversions we did till now consisted of unsigned numbers. Signed number representations are required to write negative numbers in binary number systems.
How can we represent decimal -43 in binary form? Three basic methods:
- Sign-and-magnitude method - 1s complement - 2s complement

CSC242 L02 Arithmetic Review

Sign-and-magnitude Method
Use MSB as a sign
If MSB=0, then the sign is + If MSB=1, then the sign is

Convert the following into decimal using above method:


1100, 10011110, 0110, 00110000

CSC242 L02 Arithmetic Review

Signed Numbers
1s Complement Method
Apply NOT operation on each bit to get number in 1s complement form.

2s Complement Method
Add 1 to 1s complement to get 2s complement.

CSC242 L02 Arithmetic Review

Addition
Rules
0+0 = 0 0+1 = 1 1+1 = 10 1+1+1 = 11

CSC242 L02 Arithmetic Review

10

Subtraction
Rules:
00=0 10=1 11=0 10 1 = 1

CSC242 L02 Arithmetic Review

11

Multiplication
Binary multiplication is just a bunch of right shifts and adds n
multiplicand multiplier partial product array

2n

CSC242 L02 Arithmetic Review

12

Division
Division is just a bunch of quotient digit guesses and left shifts and subtracts n n
0 0 0 divisor 0 0 0 remainder partial remainder array quotient dividend

n
CSC242 L02 Arithmetic Review 13

You might also like