You are on page 1of 25

CIS-111: Digital Logic Design

Computer Arithmetic
(Floyd: Chapters 2)

DCIS, PIEAS Javaid Khurshid


Computer Arithmetic
● Addition
● Subtraction
● Multiplication (Repetitive Addition)
● Division (Repetitive Subtraction)
● Signed Numbers
● Complements

DCIS, PIEAS Javaid Khurshid


Arithmetic Vs Logic

Please be aware of the difference between


Computer Arithmetic and Logic
Binary Addition
● Binary addition works like “Normal” Addition
– Stay within {0,1}
– Carries as usual
● Example:
Carry: 11111
111011
+ 10111
1010010

● Addition of multiple numbers possible


– Carry gets a bit more difficult

DCIS, PIEAS Javaid Khurshid


Binary Subtraction
● Subtraction same as “Normal” Subtraction
– Borrow as usual

– Example:
0 10
0 0 10
1 1 1 1 0 1
- 1 0 1 1 1
1 0 0 1 1 0

DCIS, PIEAS Javaid Khurshid


Binary Multiplication
● Binary Multiplication
● Same as “Normal “ multiplication
● Multiplication is lot easier in binary domain
● Example: 1 1 1 1 0 1
X 1 0 1 0
0 0 0 0 0 0
1 1 1 1 0 1 o
0 0 0 0 0 0 o o
1 1 1 1 0 1 o o o
1 0 0 1 1 0 0 0 1 0

DCIS, PIEAS Javaid Khurshid


Binary Division
● Same as “Normal” Division
● Example:

DCIS, PIEAS Javaid Khurshid


Signed number representations
● In Mathematics we represent a negative and
positive number with ‘-’ and ‘+’ sign respectively
● In Computers following are used
– Sign-and-Magnitude
– Ones' complement
– Two’s complement (mostly used)

DCIS, PIEAS Javaid Khurshid


Sign-and-Magnitude
● Reserve the Left Most Bit as “Sign Bit”
– ‘0’ for +(Positive number)
– ‘1’ for – (Negative number)
● Remaining bits in the number indicate the
magnitude (e.g., -43 in sign magnitude in 8 bit
number is
1 0101011
Sign bit Magnitude bits

● Easy to understand (like decimal)


● IBM 7090 used this representation
DCIS, PIEAS Javaid Khurshid
Sign-and-Magnitude…
● Example of four bit
Sign-Magnitude
number
● {-7, -6, -5, -4, -3, -2,
-1, -0, +0, +1, +2, +3,
+4, +5, +6, +7}
● Two zeros
+0 (0000)
- 0 (1000)

DCIS, PIEAS Javaid Khurshid


Sign-and-Magnitude…
● For an n-bit Sign magnitude number
● Minimum value is - (2)n-1 + 1
● Maximum value is +(2)n-1 – 1

DCIS, PIEAS Javaid Khurshid


Ones' complement
● The 1’s complement of a binary number is just the
inverse of the digits. (To form the 1’s complement,
change all 0’s to 1’s and all 1’s to 0’s.)
● the ones' complement form of
00101011 (43)10 becomes 11010100 (−43)10
● Still, two representations of zero
● PDP-1 and UNIVAC 1100/2200 series systems
used 1’s complement method for signed numbers

DCIS, PIEAS Javaid Khurshid


Ones' complement…
● Example of four bit 1’s complement number
{-7, -6, -5, -4, -3, -2, -1, -0, +0, +1, +2, +3, +4, +5, +6, +7}
0000 0001
1111
● Two zeros 1110 0010
-0 +0 +1
✔ +0 (0000) 1101
-1 +2
0011
-2 +3
✔ - 0 (1111)
1100 -3 +4 0100

-4 +5
1011 +6 0101
-5
-6 -7 +7
1010 0110
1001 0111
1000

DCIS, PIEAS Javaid Khurshid


Ones' complement…
● For an n-bit 1’s Complement number
– Minimum value is -(2)n-1 + 1
– Maximum value is +(2)n-1 – 1

DCIS, PIEAS Javaid Khurshid


Two’s Complement Representation
● Arithmetic with 2’s
complement is most
efficient 1111
0000 0001
– 1’s complement + 1 1110 0 0010
-1 +1
– Single representation 1101
-2 +2
0011
of zero! (No -3 +3

complement of +0) 1100 -4 +4 0100

– More numbers -5 +5
1011 +6 0101
-6
-7 -8 +7
1010 0110

1001 0111
1000

DCIS, PIEAS Javaid Khurshid


2s' complement…
● For an n-bit 2’s Complement number
– Minimum value is -(2)n-1
– Maximum value is +(2)n-1 – 1

DCIS, PIEAS Javaid Khurshid


3-bit numbers in different sign representations

Decimal 2's comp. 1's comp. Sign- Mag.


+3 011 011 011
+2 010 010 010
+1 001 001 001
+0 000 000 000
-0 N. A. 111 100
-1 111 110 101
-2 110 101 110
-3 101 100 111
-4 100 N. A. N. A.

DCIS, PIEAS Javaid Khurshid


Decimal Value of Signed Numbers
● Sign-magnitude
Decimal Value of Signed Numbers
● 1’s Compliment
Decimal Value of Signed Numbers
● 2’s Compliment
Floating Point Numbers
● Floating point notation is capable of representing
very large or small numbers by using a form of
scientific notation. A 32-bit single precision
number (ANSI/IEEE Standard 754-1985) is
illustrated.

S E (8 bits) F (23 bits)


Sign bit Biased exponent (+127) Magnitude with MSB dropped
Thank You

DCIS, PIEAS Javaid Khurshid

You might also like