Module 2c Aritmetic Operations
Module 2c Aritmetic Operations
FACULTY OF COMPUTING
2
3
Integer: Unsigned Number
no negative values.
4
Integer: Unsigned Number
5
Integer: Unsigned Number
range of number
Example:
6
Integer: Unsigned Number
7
Integer: Unsigned Number
Example:
4096 4095
4095
8
Integer: Signed Number
positive negative
9
10
Sign and magnitude
*Note:
A negative
number has the
same magnitude
bits as the
corresponding
positive number
but the sign bit is 0 01110
01110
1 rather than a 0. 1 100100
100100
Example:
i. +4 0 ii. -12 1
Example:
Value in
decimal?
+17
-3
12
Lower bound < decimal < Upper bound
-(24-1-1) < decimal < +(24-1-1)
-(23-1) < decimal < +(23-1)
-(8-1) < decimal < +(8-1)
-7 < decimal < +7
Example: Integer 4 bits
Positive Negative
13
Example:
-25 = - (+25)
= - (0 0 0 1 1 0 0 1) (8-bit binary system)
= 10011001
14
Complement Numbers
B’s complement
(B-1)’s complement
15
integers binary
16
1’s complement
*Note:
Positive number for (-ve)
represent the
same way as the
positive sign-
magnitude
numbers.
A negative
number is the 1’s
complement of
the corresponding - (0100100) = 1011011
positive number.
assume 7-bits binary system
-7 1000
-7 = - (+7)
= - (0 1 1 1)
= 1000 1’s
Complement
18
Example:
-25 = - (+25)
= - (0 0 0 1 1 0 0 1) (8-bit binary system)
= 11100110 1’s Complement
19
2’s complement
*Note:
Positive number
represent the
same way as the
positive sign-
magnitude
numbers.
A negative
number is the 2’s
complement of
the corresponding
positive number.
- (0100100) = 1011011 (1’s)
assume 7-bits binary system
= 1011100 (2’s)
-7 1001
2’s Complement:
1’s Complement: 1000
-7 = - (+7) + 1
= - (0 1 1 1) -----------
= 1000 1001
21
Example:
-25 = - (+25)
= - (0 0 0 1 1 0 0 1)
= 11100110 1’s Complement
= 11100111 2’s Complement
22
Example:
-23 = - (+23)
= - ( 0 0 1 0 1 1 1)
= 1101000
(7-bit binary system)
Example:
2’s Complement:
1101000
+ 1
------------------
1101001
23
Addition
25
26
Example:
Wrong result
27
Example:
-(+30) - (0 0 0 1 1 1 1 0)
Carry bit is ignored !
1 1 1 0 0 0 0 1 (1’s)
+ 1
1 1 1 0 0 0 1 0 (2’s)
28
Substraction
- (0 0 1 1 1 1)
1 1 0 0 0 0 (1’s)
1
1 1 0 0 0 1 (2’s)
29
Example:
-17 = - (+17)
= - (0 1 0 0 0 1) (6-bits)
= 1 0 1 1 1 0 (1’s)
1
1 0 1 1 1 1 (2’s)
30
Example:
101000
-9 = - (+9) -15 = - (+15)
= - (0 0 1 0 0 1) (6-bits) = - (0 0 1 1 1 1) (6-bits)
= 1 1 0 1 1 0 (1’s) = 1 1 0 0 0 0 (1’s)
1 1
1 1 0 1 1 1 (2’s) + 1 1 0 0 0 1 (2’s)
31
END OF MODULE 2
32
33
34