0% found this document useful (0 votes)
48 views68 pages

1.8B M1-Cis1102 Signed Binary Arithmetic

This document discusses signed binary addition using two's complement representation. It begins by reviewing binary arithmetic and number representation. It then provides examples of adding positive and negative signed binary numbers in 8-bit and fractional formats. For each example, it shows the step-by-step binary addition and determines the decimal values and sum. The examples cover cases where both numbers are positive, where the magnitude of the positive number is larger than the negative number, and fractional numbers.

Uploaded by

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

1.8B M1-Cis1102 Signed Binary Arithmetic

This document discusses signed binary addition using two's complement representation. It begins by reviewing binary arithmetic and number representation. It then provides examples of adding positive and negative signed binary numbers in 8-bit and fractional formats. For each example, it shows the step-by-step binary addition and determines the decimal values and sum. The examples cover cases where both numbers are positive, where the magnitude of the positive number is larger than the negative number, and fractional numbers.

Uploaded by

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

CIS 1102

INTRODUCTION TO COMPUTING

SIGNED BINARY
RECALL: BINARY ARITHMETIC
 It is used in digital systems mainly because the numbers (decimal and floating-
point numbers) are stored in binary format.

 All arithmetic operations such as addition, subtraction, multiplication, and


division are done in binary representation of numbers.

 It is necessary to understand the binary number representation to figure out


binary arithmetic in digital computers.

 In most ALU (Arithmetic & Logic Unit) hardware, the operated numbers are
stored in a fixed number of bits, a typical value between 4 and 16 decimal digits

 There is a precision limit or precision error performing binary arithmetic on


computers.

 This binary arithmetic is called fixed-precision arithmetic.

CIS 1102 – ITC


BINARY ADDITION RULES

 Binary addition is carried out Augend + Addend = Sum Carry


just like decimal, by adding up
the columns, starting at the 0 + 0 = 0 0
right and working column by 0 + 1 = 1 0
column towards the left.
1 + 0 = 1 0
 Just as in decimal addition, 1 + 1 = 0 1
sometimes a ‘carry’ occurs, and
it is added to the next column.
 NOTE:
• 1 + 1 is equal to 10 (in hardware, sum = 0; carry = 1)
• 1 + 1 + 1 is equal to 11 (in hardware, sum = 1; carry = 1)

CIS 1102 – ITC


SIGNED BINARY ADDITION USING 2’s COMPLEMENT: EX1
Case 1: Both Numbers are Positive
Given:
A = 01000111
B = 00100101

Tasks:
a) Calculate the sum of the given 8-bit signed binary numbers. Show the complete details of the
solution.
b) Determine the decimal number equivalent of the given 8-bit signed binary numbers and their
sum. Show the complete details of the solution.

CIS 1102 – ITC


SIGNED BINARY ADDITION USING 2’s COMPLEMENT: EX1
Case 1: Both Numbers are Positive
a) Calculate the sum of the given 8-bit signed numbers. Show the complete details of the solution.

Carry 1 1 1

Augend (A) 0 1 0 0 0 1 1 1

Addend (B) 0 0 1 0 0 1 0 1

Final Sum 0 1 1 0 1 1 0 0

CIS 1102 – ITC


SIGNED BINARY ADDITION USING 2’s COMPLEMENT: EX1
b) Determine the decimal number equivalent of the given 8-bit signed numbers and their sum. Show the complete
details of the solution.

Weights 128 64 32 16 8 4 2 1
Binary Augend (A) 0 1 0 0 0 1 1 1
Decimal Augend (A) 64 + 4 + 2 + 1 = +71

Weights 128 64 32 16 8 4 2 1
Binary Addend (B) 0 0 1 0 0 1 0 1
Decimal Addend (B) 32 + 4 + 1 = +37

Decimal Sum (+71) +(+37) = +108

CIS 1102 – ITC


SIGNED BINARY ADDITION USING 2’s COMPLEMENT: EX2
Case 2: Both Numbers are Positive
Given:
C = 00100111.11
D = 00010100.01

Tasks:
a) Calculate the sum of the given signed binary numbers. Show the complete details of the
solution.
b) Determine the decimal number equivalent of the given signed binary numbers and their sum.
Show the complete details of the solution.

CIS 1102 – ITC


SIGNED BINARY ADDITION USING 2’s COMPLEMENT: EX2
Case 2: Both Numbers are Positive
a) Calculate the sum of the given signed binary numbers. Show the complete details of the solution.

Carry 1 1 1 1 1

Augend (C) 0 0 1 0 0 1 1 1 . 1 1

Addend (D) 0 0 0 1 0 1 0 0 . 0 1

Final Sum 0 0 1 1 1 1 0 0 . 0 0

CIS 1102 – ITC


SIGNED BINARY ADDITION USING 2’s COMPLEMENT: EX2
b) Determine the decimal number equivalent of the given signed binary numbers and their sum. Show the
complete details of the solution.

Weights 128 64 32 16 8 4 2 1 0.5 0.25


Binary Augend (C) 0 0 1 0 0 1 1 1 . 1 1
Decimal Augend (C) 32 + 4 + 2 + 1 + 0.5 + 0.25 = +39.75

Weights 128 64 32 16 8 4 2 1 0.5 0.25


Binary Addend (D) 0 0 0 1 0 1 0 0 . 0 1
Decimal Addend (D) 16 + 4 + 0.25 = +20.25

Decimal Sum (+39.75) + (+20.25) = +60.00 or +60

CIS 1102 – ITC


SIGNED BINARY ADDITION USING 2’s COMPLEMENT: EX3
Case 3: Positive Number with Magnitude Larger than the Negative Number
Given:
E = 00010111
F = 11111000

Tasks:
a) Calculate the sum of the given 8-bit signed binary numbers. Show the complete details of the
solution.
b) Determine the decimal number equivalent of the given 8-bit signed binary numbers and their
sum. Show the complete details of the solution.

CIS 1102 – ITC


SIGNED BINARY ADDITION USING 2’s COMPLEMENT: EX3
Case 3: Positive Number with Magnitude Larger than the Negative Number
a) Calculate the sum of the given 8-bit signed numbers. Show the complete details of the solution.

Carry 1 1 1 1

Augend (E) 0 0 0 1 0 1 1 1

Addend (F) 1 1 1 1 1 0 0 0

Final Sum 1 0 0 0 0 1 1 1 1

Discard

CIS 1102 – ITC


SIGNED BINARY ADDITION USING 2’s COMPLEMENT: EX3
b) Determine the decimal number equivalent of the given 8-bit signed numbers and their sum. Show the complete
details of the solution.

Weights 128 64 32 16 8 4 2 1
Binary Augend (E) 0 0 0 1 0 1 1 1
Decimal Augend (E) 16 + 4 + 2 + 1 = + 23

Binary Addend (F) 1 1 1 1 1 0 0 0


2’s Complement of F 0 0 0 0 1 0 0 0
Weights 128 64 32 16 8 4 2 1
Decimal Addend (F) 8 = - 8 (Sign Bit of F = 1; negative number)

Decimal Sum (+23) + (-8) = +15

CIS 1102 – ITC


SIGNED BINARY ADDITION USING 2’s COMPLEMENT: EX3
b) Determine the decimal number equivalent of the given 8-bit signed numbers and their sum. Show the complete
details of the solution.

Counterchecking: Using Signed 2’s Complement Evaluation

Weights 128 64 32 16 8 4 2 1
Binary Augend (E) 0 0 0 1 0 1 1 1
Decimal Augend (E) 16 + 4 + 2 + 1 = + 23

Weights -128 64 32 16 8 4 2 1
Binary Addend (F) 1 1 1 1 1 0 0 0
Decimal Addend (F) -128 + 64 + 32 + 16 + 8 = -128 + 120 = - 8

Decimal Sum (+23) + (-8) = + 15

CIS 1102 – ITC


SIGNED BINARY ADDITION USING 2’s COMPLEMENT: EX4
Case 4: Positive Number with Magnitude Larger than the Negative Number
Given:
G = 00100110.11
H = 11111001.10

Tasks:
a) Calculate the sum of the given signed binary numbers. Show the complete details of the
solution.
b) Determine the decimal number equivalent of the given signed binary numbers and their sum.
Show the complete details of the solution.

CIS 1102 – ITC


SIGNED BINARY ADDITION USING 2’s COMPLEMENT: EX4
Case 4: Positive Number with Magnitude Larger than the Negative Number
a) Calculate the sum of the given signed binary numbers. Show the complete details of the solution.

Carry 1 1 1 1 1 1 1 1 1

Augend (G) 0 0 1 0 0 1 1 0 . 1 1

Addend (H) 1 1 1 1 1 0 0 1 . 1 0

Final Sum 1 0 0 1 0 0 0 0 0 . 0 1

Discard

CIS 1102 – ITC


SIGNED BINARY ADDITION USING 2’s COMPLEMENT: EX4
b) Determine the decimal number equivalent of the given signed binary numbers and their sum. Show the
complete details of the solution.

Weights 128 64 32 16 8 4 2 1 0.5 0.25


Binary Augend (G) 0 0 1 0 0 1 1 0 . 1 1
Decimal Augend (G) 32 + 4 + 2 + 0.5 + 0.25 = + 38.75

Binary Addend (H) 1 1 1 1 1 0 0 1 . 1 0


Remove radix point 1 1 1 1 1 0 0 1 1 0
2’s Complement of H 0 0 0 0 0 1 1 0 1 0
Weights 128 64 32 16 8 4 2 1
Decimal Addend (H) 4 + 2 + 0.5 = - 6.5 (Sign Bit of H = 1; negative number)

Decimal Sum (+38.75) + (-6.5) = +32.25

CIS 1102 – ITC


SIGNED BINARY ADDITION USING 2’s COMPLEMENT: EX4
b) Determine the decimal number equivalent of the given signed binary numbers and their sum. Show the
complete details of the solution.

Counterchecking: Using Signed 2’s Complement Evaluation

Weights 128 64 32 16 8 4 2 1 0.5 0.25


Binary Augend (G) 0 0 1 0 0 1 1 0 . 1 1
Decimal Augend (G) 32 + 4 + 2 + 0.5 + 0.25 = + 38.75

Weights -128 64 32 16 8 4 2 1 0.5 0.25


Binary Addend (H) 1 1 1 1 1 0 0 1 . 1 0
Decimal Addend (H) -128 + 64 + 32 + 16 + 8 + 1 + 0.5 = -128 + 121.5 = - 6.5

Decimal Sum (+38.75) + (-6.5) = + 32.25

CIS 1102 – ITC


2’s or 1’s Complement: Important Notes

 If the original number N contains a radix point:


o the point should be removed temporarily in order to form the 2’s or 1’s complement
o the radix point is then restored to the complemented number in the same relative
position.

 The complement of the complement restores the number to its original value.
o To see this relationship,
 note that the 2’s complement of N is rn - N,
 so that the complement of the complement is rn – (rn – N) = N
 and is equal to the original number.

CIS 1102 – ITC


SIGNED BINARY ADDITION USING 2’s COMPLEMENT: EX5
Case 5: Negative Number with Magnitude Larger than the Positive Number
Given:
I = 00010001.011
J = 11001111.100

Tasks:
a) Calculate the sum of the given signed binary numbers. Show the complete details of the
solution.
b) Determine the decimal number equivalent of the given signed binary numbers and their sum.
Show the complete details of the solution.

CIS 1102 – ITC


SIGNED BINARY ADDITION USING 2’s COMPLEMENT: EX5
Case 5: Negative Number with Magnitude Larger than the Positive Number
a) Calculate the sum of the given signed binary numbers. Show the complete details of the solution.

Carry 1 1 1 1 1

Augend (I) 0 0 0 1 0 0 0 1 . 0 1 1

Addend (J) 1 1 0 0 1 1 1 1 . 1 0 0

Final Sum 1 1 1 0 0 0 0 0 . 1 1 1

Remove radix point 1 1 1 0 0 0 0 0 1 1 1

2’s Complement of Sum 0 0 0 1 1 1 1 1 . 0 0 1

CIS 1102 – ITC


SIGNED BINARY ADDITION USING 2’s COMPLEMENT: EX5
b) Determine the decimal number equivalent of the given signed binary numbers and their sum. Show the
complete details of the solution.

Weights 128 64 32 16 8 4 2 1 0.5 0.25 0.125


Binary Augend (I) 0 0 0 1 0 0 0 1 . 0 1 1
Decimal Augend (I) 16 + 1 + 0.25 + 0.125 = +17.375

Binary Addend (J) 1 1 0 0 1 1 1 1 . 1 0 0


Remove radix point 1 1 0 0 1 1 1 1 1 0 0
2’s Complement of J 0 0 1 1 0 0 0 0 1 0 0
Weights 128 64 32 16 8 4 2 1 0.5 0.25 0.125
Decimal Addend (J) 32 + 16 + 0.5 = - 48.5 (Sign Bit of J = 1; negative number)

Decimal Sum (+17.375) + (-48.5) = - 31.125

CIS 1102 – ITC


SIGNED BINARY ADDITION USING 2’s COMPLEMENT: EX5
b) Determine the decimal number equivalent of the given signed binary numbers and their sum. Show the
complete details of the solution.

Counterchecking: Using Signed 2’s Complement Evaluation

Weights 128 64 32 16 8 4 2 1 0.5 0.25 0.125


Binary Augend (I) 0 0 0 1 0 0 0 1 . 0 1 1
Decimal Augend (I) 16 + 1 + 0.25 + 0.125 = +17.375

Weights -128 64 32 16 8 4 2 1 0.5 0.25 0.125


Binary Addend (J) 1 1 0 0 1 1 1 1 . 1 0 0
Decimal Addend (J) -128 + 64 + 8 + 4 + 2 + 1 + 0.5 = -128 + 79.5 = - 48.5

Decimal Sum (+17.375) + (-48.5) = - 31.125

CIS 1102 – ITC


SIGNED BINARY ADDITION USING 2’s COMPLEMENT: EX6
Case 6: Both Numbers are Negative
Given:
K = 11111011.101
L = 11110111.011

Tasks:
a) Calculate the sum of the given signed binary numbers. Show the complete details of the
solution.
b) Determine the decimal number equivalent of the given signed binary numbers and their sum.
Show the complete details of the solution.

CIS 1102 – ITC


SIGNED BINARY ADDITION USING 2’s COMPLEMENT: EX6
Case 6: Both Numbers are Negative
a) Calculate the sum of the given signed binary numbers. Show the complete details of the solution.

Carry 1 1 1 1 1 1 1 1 1 1 1

Augend (K) 1 1 1 1 1 0 1 1 . 1 0 1

Addend (L) 1 1 1 1 0 1 1 1 . 0 1 1

Final Sum 1 1 1 1 1 0 0 1 1 0 0 0
Discard

Final Sum 1 1 1 1 0 0 1 1 . 0 0 0
Remove radix point 1 1 1 1 0 0 1 1 0 0 0
2’s Complement of Sum 0 0 0 0 1 1 0 1 . 0 0 0

CIS 1102 – ITC


SIGNED BINARY ADDITION USING 2’s COMPLEMENT: EX6
b) Determine the decimal number equivalent of the given signed binary numbers and their sum. Show the
complete details of the solution.
Binary Addend (K) 1 1 1 1 1 0 1 1 . 1 0 1
Remove radix point 1 1 1 1 1 0 1 1 1 0 1
2’s Complement of K 0 0 0 0 0 1 0 0 0 1 1
Weights 128 64 32 16 8 4 2 1 0.5 0.25 0.125
Decimal Addend (K) 4 + 0.25 + 0.125 = - 4.375 (Sign Bit of K = 1; negative number)
Binary Addend (L) 1 1 1 1 0 1 1 1 . 0 1 1
Remove radix point 1 1 1 1 0 1 1 1 0 1 1
2’s Complement of L 0 0 0 0 1 0 0 0 1 0 1
Weights 128 64 32 16 8 4 2 1 0.5 0.25 0.125
Decimal Addend (L) 8 + 0.5 + 0.125 = - 8.625 (Sign Bit of L = 1; negative number)

Decimal Sum (- 4.375) + (- 8.625) = - 13.000 or - 13

CIS 1102 – ITC


SIGNED BINARY ADDITION USING 2’s COMPLEMENT: EX6
b) Determine the decimal number equivalent of the given signed binary numbers and their sum. Show the
complete details of the solution.

Counterchecking: Using Signed 2’s Complement Evaluation

Weights -128 64 32 16 8 4 2 1 0.5 0.25 0.125


Binary Augend (K) 1 1 1 1 1 0 1 1 . 1 0 1
Decimal Augend (K) -128 + 64 + 32 + 16 + 8 + 2 + 1 + 0.5 + 0.125 = -128 + 123.625 = - 4.375

Weights -128 64 32 16 8 4 2 1 0.5 0.25 0.125


Binary Addend (L) 1 1 1 1 0 1 1 1 . 0 1 1
Decimal Addend (L) -128 + 64 + 32 + 16 + 4 + 2 + 1 + 0.25 + 0.125 = -128 + 119.375 = - 8.625

Decimal Sum (- 4.375) + (- 8.625) = - 13.000 or - 13

CIS 1102 – ITC


SIGNED-2’s COMPLEMENT ADDITION: OVERFLOW RULE

 When both numbers are positive or both numbers are negative and the
result has the opposite sign

 Overflow never occurs when adding operands with different signs.

CIS 1102 – ITC


OVERFLOW CONDITION: EXAMPLE 1

Given:
M = 01111101
N = 00111010

Tasks:
a) Calculate the sum of the given 8-bit signed binary numbers and check for an overflow. Show
the complete details of the solution.
b) Determine the decimal number equivalent of the given 8-bit signed binary numbers and their
sum to countercheck the result of Task (a). Show the complete details of the solution.

CIS 1102 – ITC


OVERFLOW CONDITION: EXAMPLE 1

a) Calculate the sum of the given 8-bit signed numbers and check for an overflow. Show the complete details of
the solution.

Carry 1 1 1 1

Augend (M) 0 1 1 1 1 1 0 1

Addend (N) 0 0 1 1 1 0 1 0

Final Sum 1 0 1 1 0 1 1 1

CIS 1102 – ITC


OVERFLOW CONDITION: EXAMPLE 1
b) Determine the decimal number equivalent of the given 8-bit signed numbers and their sum to countercheck the
result of Task (a). Show the complete details of the solution.

Counterchecking

Weights 128 64 32 16 8 4 2 1 Range (2’s complement):


Binary Augend (M) 0 1 1 1 1 1 0 1
[ -2n-1 to +2n-1 - 1]
Decimal Augend (M) 64 + 32 + 16 + 8 + 4 + 1 = +125 || n = 8 bits||
Weights 128 64 32 16 8 4 2 1
[ -28-1 to +28-1 - 1]
Binary Addend (N) 0 0 1 1 1 0 1 0 [ -27 to +27 - 1]
Decimal Addend (N) 32 + 16 + 8 + 2 = +58 [ -128 to +128 - 1]
[ -128 to +127]
Decimal Sum (+125) + (+58) = +183

Note: Decimal Sum exceeds +127, therefore, there is an overflow.

CIS 1102 – ITC


OVERFLOW CONDITION: EXAMPLE 2

Given:
O = 10001001
P = 10111010

Tasks:
a) Calculate the sum of the given 8-bit signed binary numbers and check for an overflow. Show
the complete details of the solution.
b) Determine the decimal number equivalent of the given 8-bit signed binary numbers and their
sum to countercheck the result of Task (a). Show the complete details of the solution.

CIS 1102 – ITC


OVERFLOW CONDITION: EXAMPLE 2

a) Calculate the sum of the given 8-bit signed numbers and check for an overflow. Show the complete details of
the solution.

Carry 1 1 1

Augend (O) 1 0 0 0 1 0 0 1

Addend (P) 1 0 1 1 1 0 1 0

Final Sum 1 0 1 0 0 0 0 1 1
Discard

CIS 1102 – ITC


OVERFLOW CONDITION: EXAMPLE 2
b) Determine the decimal number equivalent of the given 8-bit signed numbers and their sum to countercheck the
result of Task (a). Show the complete details of the solution.

Counterchecking

Range (2’s complement):


Weights -128 64 32 16 8 4 2 1
[ -2n-1 to +2n-1 - 1]
Binary Augend (O) 1 0 0 0 1 0 0 1
|| n = 8 bits||
Decimal Augend (O) -128 + 8 + 1 = -128 + 9 = -119
[ -28-1 to +28-1 - 1]
Weights -128 64 32 16 8 4 2 1 [ -27 to +27 - 1]
Binary Addend (P) 1 0 1 1 1 0 1 0 [ -128 to +128 - 1]
Decimal Addend (P) -128 + 32 + 16 + 8 + 2 = -128 + 58 = -70 [ -128 to +127]
Note:
Decimal Sum (-119) + (-70) = -189 Decimal Sum (-189) exceeds the
smallest number (-127), therefore,
there is an overflow.

CIS 1102 – ITC


SIGNED BINARY SUBTRACTION

 A computer cannot subtract a number from another.

 It can only add two numbers.


o Example: Subtract B from A
• A – B → not this way
• A + (-B) → this is the way

 In computer arithmetic: Complement Method (A + (-B))

CIS 1102 – ITC


SUBTRACTION WITH COMPLEMENTS

RECALL

 The direct method of subtraction taught in elementary schools uses the borrow concept.
o 1 is borrowed from a higher significant position when the minuend digit is smaller
than the subtrahend digit

 The method works well when people perform subtraction with paper and pencil.

 However, when subtraction is implemented with digital hardware, the method is less
efficient than the method that uses complements.

CIS 1102 – ITC


SUBTRACTION WITH 2’s COMPLEMENT

 Algorithm:

1. Take the 2’s complement of the Subtrahend.

2. Add the result of Step 1 to the Minuend.

3. Check the result of Step 2 for an end carry:


a) If an end carry occurs, discard it, and the final result is left.
b) If an end carry does not occur, take the 2’s complement of the result of
Step 2 then place a negative sign in front (this is done to obtain a familiar
form of the final result).

CIS 1102 – ITC


BINARY SUBTRACTION – 2’S COMPLEMENT: EXAMPLE 1
Given:

(110101)2 - (101110)2

Tasks:
a) Find the difference of the given signed numbers using 2’s Complement
Method. Show the complete details of the solution.
b) Compute the decimal number equivalent of the given numbers and their
difference. Show the complete details of the solution.

CIS 1102 – ITC


BINARY SUBTRACTION – 2’S COMPLEMENT: E1 SOLUTION
a) Find the difference of the given signed numbers using 2’s Complement Method. Show the complete details of
the solution.

Step 1: Take the 2’s complement of the Subtrahend. Subtrahend 1 0 1 1 1 0


Invert bits 0 1 0 0 0 1
Plus 1 + 1
0 1 0 0 1 0
Step 2: Add the result of Step 1 to the Minuend. Minuend 1 1 0 1 0 1
Step 1 Result + 0 1 0 0 1 0
Step 2 Result 1 0 0 0 1 1 1
Step 3: Check the result of Step 2 for an end carry:
If an end carry occurs, discard it. Final Result 0 0 0 1 1 1

Therefore: (110101)2 - (101110)2 = (000111)2

CIS 1102 – ITC


BINARY SUBTRACTION – 2’S COMPLEMENT: E1 SOLUTION
b) Compute the decimal number equivalent of the given numbers and their difference. Show the complete details
of the solution.
Counterchecking

Minuend 1 1 0 1 0 1
Weights -32 16 8 4 2 1
Decimal Equivalent -32 + 16 + 4 + 1 = -32 + 21 = -11
Subtrahend 1 0 1 1 1 0
Weights -32 16 8 4 2 1
Decimal Equivalent -32 + 8 + 4 + 2 = -32 + 14 = -18
Difference 0 0 0 1 1 1
Weights 32 16 8 4 2 1
Decimal Equivalent 4 + 2 + 1 = +7
Final Answer: (-11) – (-18) = (-11 + 18) = +7

CIS 1102 – ITC


BINARY SUBTRACTION – 2’S COMPLEMENT: EXAMPLE 2

Given:

(101110)2 - (110101)2

Tasks:
a) Find the difference of the two signed binary numbers given above using 2’s
Complement Method. Show the complete details of the solution.
b) Compute the decimal number equivalent of the given numbers and their
difference. Show the complete details of the solution.

CIS 1102 – ITC


BINARY SUBTRACTION – 2’S COMPLEMENT: E2 SOLUTION
a) Find the difference of the two signed binary numbers given above using 2’s Complement Method. Show the
complete details of the solution.
Step 1: Take the 2’s complement of the Subtrahend. Subtrahend 1 1 0 1 0 1
Invert bits 0 0 1 0 1 0
Plus 1 + 1
0 0 1 0 1 1
Step 2: Add the result of Step 1 to the Minuend. Minuend 1 0 1 1 1 0
Step 1 Result + 0 0 1 0 1 1
Step 2 Result 1 1 1 0 0 1
Step 3: Check the result of Step 2 for an end carry:
If an end carry does not occur, take the 2’s Step 2 Result 1 1 1 0 0 1
Complement of Step 2 result then place a Invert bits 0 0 0 1 1 0
negative sign in front. Plus 1 + 1
Familiar Form - 0 0 0 1 1 1
Therefore: (101110)2 - (110101)2 = (111001)2 = - (000111)2

CIS 1102 – ITC


BINARY SUBTRACTION – 2’S COMPLEMENT: E2 SOLUTION
b) Compute the decimal number equivalent of the given numbers and their difference. Show the complete details
of the solution.
Counterchecking

Minuend 1 0 1 1 1 0
Weights -32 16 8 4 2 1
Decimal Equivalent -32 + 8 + 4 + 2 = -32 + 14 = -18
Subtrahend 1 1 0 1 0 1
Weights -32 16 8 4 2 1
Decimal Equivalent -32 + 16 + 4 + 1 = -32 + 21 = -11
Difference 1 1 1 0 0 1
Weights -32 16 8 4 2 1
Decimal Equivalent -32 + 16 + 8 + 1 = -32 + 25 = -7
Final Answer: (-18) – (-11) = (-18 + 11) = -7

CIS 1102 – ITC


SUBTRACTION WITH 1’s COMPLEMENT

 Algorithm:

1. Take the 1’s complement of the Subtrahend.

2. Add the result of Step 1 to the Minuend.

3. Check the result of Step 2 for an end carry:


a) If an end carry occurs, remove it and add 1 to Step 2 result.
b) If an end carry does not occur, take the 1’s complement of the result of
Step 2 then place a negative sign in front (this is done to obtain a familiar
form of the final result).

CIS 1102 – ITC


BINARY SUBTRACTION – 1’S COMPLEMENT: EXAMPLE 1
Given:

(110101)2 - (101110)2

Tasks:
a) Find the difference of the two signed binary numbers given above using 1’s
Complement Method. Show the complete details of the solution.
b) Compute the decimal number equivalent of the given numbers and their
difference. Show the complete details solution.

CIS 1102 – ITC


BINARY SUBTRACTION – 1’S COMPLEMENT: E1 SOLUTION
a) Find the difference of the two signed binary numbers given above using 1’s Complement Method. Show the
complete details of the solution.

Step 1: Take the 1’s complement of the Subtrahend. Subtrahend 1 0 1 1 1 0


Invert bits 0 1 0 0 0 1
Step 2: Add the result of Step 1 to the Minuend. Minuend 1 1 0 1 0 1
Step 1 Result + 0 1 0 0 0 1
Step 2 Result 1 0 0 0 1 1 0
Step 3: Check the result of Step 2 for an end carry:
If an end carry occurs, remove it and add 1 to 0 0 0 1 1 0
the result of Step 2 (end-around carry). + 1
0 0 0 1 1 1

Therefore: (110101)2 - (101110)2 = (000111)2

CIS 1102 – ITC


BINARY SUBTRACTION – 1’S COMPLEMENT: E1 SOLUTION
b) Compute the decimal number equivalent of the given numbers and their difference. Show the complete details of the
solution.

Counterchecking

Minuend 1 1 0 1 0 1
Weights -31 16 8 4 2 1 Weight of Sign Bit:
Decimal Equivalent -31 + 16 + 4 + 1 = -31 + 21 = -10
W = (-2n + 1)
Subtrahend 1 0 1 1 1 0
Weights -31 16 8 4 2 1 || n = 5 (position) ||
Decimal Equivalent -31 + 8 + 4 + 2 = -31 + 14 = -17
W = (-25 + 1)
Difference 0 0 0 1 1 1 W = (-32 + 1)
Weights 32 16 8 4 2 1 W = (-31)
Decimal Equivalent 4 + 2 + 1 = +7

Final Answer: (-10) – (-17) = (-10 + 17) = +7

CIS 1102 – ITC


BINARY SUBTRACTION – 1’S COMPLEMENT: EXAMPLE 2

Given:

(101110)2 - (110101)2

Tasks:
a) Find the difference of the two signed binary numbers given above using 1’s
Complement Method. Show the complete details of the solution.
b) Compute the decimal number equivalent of the given numbers and their
difference. Show the complete details of the solution.

CIS 1102 – ITC


BINARY SUBTRACTION – 1’S COMPLEMENT: E2 SOLUTION

a) Find the difference of the two signed binary numbers given above using 1’s Complement Method. Show the
complete solution.

Step 1: Take the 1’s complement of the Subtrahend. Subtrahend 1 1 0 1 0 1


Invert bits 0 0 1 0 1 0
Step 2: Add the result of Step 1 to the Minuend. Minuend 1 0 1 1 1 0
Step 1 Result + 0 0 1 0 1 0
Step 2 Result 1 1 1 0 0 0
Step 3: Check the result of Step 2 for an end carry:
If an end carry does not occur, take the 1’s No end carry 1 1 1 0 0 0
complement of Step 2 result then place a Invert bits 0 0 0 1 1 1
negative sign in front. Familiar form - 0 0 0 1 1 1

Therefore: (101110)2 - (110101)2 = (111000)2 = - (000111)2

CIS 1102 – ITC


BINARY SUBTRACTION – 1’S COMPLEMENT: E2 SOLUTION
b) Compute the decimal number equivalent of the given numbers and their difference. Show the complete details of the
solution.

Counterchecking

Minuend 1 0 1 1 1 0 Final Answer:


Weights -31 16 8 4 2 1
(-17) – (-10) = (-17 + 10) = -7
Decimal Equivalent -31 + 8 + 4 + 2 = -31 + 14 = -17

Subtrahend 1 1 0 1 0 1
Weights -31 16 8 4 2 1
Decimal Equivalent -31 + 16 + 4 + 1 = -31 + 21 = -10

Difference 1 1 1 0 0 0
Weights -31 16 8 4 2 1
Decimal Equivalent -31 + 16 + 8 = -31 + 24 = -7

CIS 1102 – ITC


BINARY MULTIPLICATION: RULES

Multiplicand x Multiplier = Product


0 x 0 = 0
0 x 1 = 0
1 x 0 = 0
1 x 1 = 1

CIS 1102 – ITC


BINARY MULTIPLICATION WITH 2’S COMPLEMENT

 Algorithm:

1. Convert both multiplicand and multiplier to positive numbers.

2. Perform the multiplication operation of positive numbers.

3. Then take the 2’s complement of the result if and only if the sign of the
two original numbers differed from each other.

CIS 1102 – ITC


SIGNED BINARY MULTIPLICATION: EXAMPLE 1

Given:

(1110)2 x (0101)2

Tasks:
a) Find the product of the two signed binary numbers given above using 2’s
Complement Method. Express the partial products and the final result in 8 bits.
Show the complete details of the solution.
b) Compute the decimal number equivalent of the given numbers and their
difference. Show the complete details of the solution.

CIS 1102 – ITC


SIGNED BINARY MULTIPLICATION: EXAMPLE 1
a) Find the product of the two signed binary numbers given above using 2’s Complement Method. Show the
complete details of the solution.

Multiplicand Original 1 1 1 0
Multiplicand (+) 0 0 1 0
Multiplier x 0 1 0 1
0 0 0 0 0 0 1 0
0 0 0 0 0 0 0 0
Partial Products
0 0 0 0 1 0 0 0
0 0 0 0 0 0 0 0
Final Product (FP) Original 0 0 0 0 1 0 1 0
FP (2’s Complement) 1 1 1 1 0 1 1 0

Final Answer: (1110)2 x (0101)2 = (11110110)2

CIS 1102 – ITC


SIGNED BINARY MULTIPLICATION: EXAMPLE 1
b) Determine the decimal number equivalent of the given numbers and their product. Show the complete details of
the solution.
Counterchecking

Multiplicand 1 1 1 0
Weights -8 4 2 1
Decimal Equivalent -8 + 4 + 2 = -8 + 6 = -2

Multiplier 0 1 0 1
Weights 8 4 2 1
Decimal Equivalent 4 + 1 = +5

Final Product 1 1 1 1 0 1 1 0
Weights -128 64 32 16 8 4 2 1
Decimal Equivalent -128 + 64 + 32 + 16 + 4 + 2 = -128 + 118 = -10

Final Answer: (-2)10 x (+5)10 = (-10)10

CIS 1102 – ITC


SIGNED BINARY MULTIPLICATION: EXAMPLE 2

Given:
Q = (-5)10
R = (-6)10

Tasks:
a) Find the product of Q and R, expressed in 4 bits each, using 2’s Complement
Method. Express the partial products and the final result in 8 bits. Show the
complete details of the solution.
b) Compute the decimal number equivalent of the given numbers and their
difference. Show the complete details of the solution.

CIS 1102 – ITC


SIGNED BINARY MULTIPLICATION: EXAMPLE 2
a) Find the product of Q and R, expressed in 4 bits each, using 2’s Complement Method. Express the partial
products and the final result in 8 bits. Show the complete details of the solution.

Multiplicand Original (Q) 1 0 1 1


Multiplier Original (R) 1 0 1 0
Multiplicand (+Q) 0 1 0 1
Multiplier (+R) x 0 1 1 0
0 0 0 0 0 0 0 0
0 0 0 0 1 0 1 0
Partial Products
0 0 0 1 0 1 0 0
0 0 0 0 0 0 0 0
Final Product (FP) 0 0 0 1 1 1 1 0

Final Answer: (1011)2 x (1010)2 = (00011110)2

CIS 1102 – ITC


SIGNED BINARY MULTIPLICATION: EXAMPLE 2
b) Determine the decimal number equivalent of the given numbers and their product. Show the complete details of
the solution.
Counterchecking

Multiplicand 1 0 1 1
Weights -8 4 2 1
Decimal Equivalent -8 + 2 + 1 = -8 + 3 = -5

Multiplier 1 0 1 0
Weights -8 4 2 1
Decimal Equivalent -8 + 2 = -6

Final Product 0 0 0 1 1 1 1 0
Weights 128 64 32 16 8 4 2 1
Decimal Equivalent 16 + 8 + 4 + 2 = +30

Final Answer: (-5)10 x (-6)10 = (+30)10

CIS 1102 – ITC


DIVISION with NEGATIVE NUMBERS: PROCEDURE

 Convert the operands into positive values

 Perform the division operation using the Restoring Division Flowchart and
Algorithm for signed numbers

 Account for the signs by complementation (where needed)

CIS 1102 – ITC


DIVISION with NEGATIVE NUMBERS: DERIVED SIGNS

 Sign (R) = Sign (D)


 Sign (Q) = Sign (D) x Sign (V)

where:
R = Remainder
D = Dividend
V = DiVisor
Q = Quotient

CIS 1102 – ITC


RESTORING DIVISION FLOWCHART

CIS 1102 – ITC


RESTORING DIVISION ALGORITHM

1. Both the dividend and divisor must be positive.


• Load the dividend into the A and Q registers.
• The dividend must be expressed as a 2n-bit positive number.
Thus, for example, the 4-bit 0111 (i.e., n=4) becomes 00000111 (i.e., 2n).
• Load the 2’s complement of the divisor into the M register.
M register contains the negative of the divisor

2. Shift A, Q left 1 bit position.

3. Perform A ← A – M
• since M = 2’s complement of the original divisor, thus, perform A ← A + M

CIS 1102 – ITC


RESTORING DIVISION ALGORITHM

4. a) If the result is nonnegative (MSB of A = 0), then set Q0 = 1.


b) If the result is negative (MSB of A = 1), set Q0 = 0, and restore the previous value of A.

5. Repeat steps 2 through 4 as many times as there are n bit positions in Q (dividend).

6. The remainder is in A and the quotient is in Q.

CIS 1102 – ITC


SIGNED BINARY DIVISION: EXAMPLE 1

Given:
S = (-5)10
T = (-2)10

Task:
Find the quotient and remainder of dividing S by T using the procedure of
performing division with negative numbers.
• Express the dividend in 8 bits (load to A & Q)
• Express the divisor in 4 bits (load 2’s complement of +T to M)
• Show the sequence of events of the operation
• Express the final answer in decimal and binary forms

CIS 1102 – ITC


SIGNED BINARY DIVISION: EXAMPLE 1
Sequence of Events of the Operation

A Q M n
(Q3Q2Q1Q0)  Signs:
0000 0101 1110 4 Initial Values
Sign(Q) = Sign(D) x Sign(V)
0000 1010 1110 3 Shift Left A,Q
1110 1010 1110 A ← A + M; MSB(A) = 1
Sign(Q) = (-) x (-) = (+)
0000 1010 1110 Restore Previous A ; Set Q0 = 0
Sign(R) = Sign(D)
0001 0100 1110 2 Shift Left A,Q
1111 0100 1110 A ← A + M; MSB(A) = 1
Sign(R) = (-)
0001 0100 1110 Restore Previous A ; Set Q0 = 0
0010 1000 1110 1 Shift Left A,Q  Final Answer:
0000 1000 1110 A ← A + M; MSB(A) = 0
0000 1001 1110 Set Q0 = 1
Q: Quotient = (+2)10 = 00102
0001 0010 1110 0 Shift Left A,Q A: Remainder = (-1)10 = 11112
1111 0010 1110 A ← A + M; MSB(A) = 1
0001 0010 1110 Restore Previous A ; Set Q0 = 0

CIS 1102 – ITC


SIGNED BINARY DIVISION: EXAMPLE 2

Given:
U = (+7)10
V = (+3)10

Task:
Find the quotient and remainder of dividing U by V using the procedure
of performing division with negative numbers.
• Express the dividend in 8 bits (load to A & Q)
• Express the divisor in 4 bits (load 2’s complement of +V to M)
• Show the sequence of events of the operation
• Express the final answer in binary and decimal forms

CIS 1102 – ITC


SIGNED BINARY DIVISION: EXAMPLE 2
Sequence of Events of the Operation

A Q M n
(Q3Q2Q1Q0)  Signs:
0000 0111 1101 4 Initial Values
Sign(Q) = Sign(D) x Sign(V)
0000 1110 1101 Shift Left A,Q
1101 1110 1101 A ← A + M; MSB(A) = 1
Sign(Q) = (+) x (+) = (+)
0000 1110 1101 3 Restore Previous A ; Set Q0 = 0
Sign(R) = Sign(D)
0001 1100 1101 Shift Left A,Q
1110 1100 1101 A ← A + M; MSB(A) = 1
Sign(R) = (+)
0001 1100 1101 2 Restore Previous A ; Set Q0 = 0
0011 1000 1101 Shift Left A,Q  Final Answer:
0000 1000 1101 A ← A + M; MSB(A) = 0
0000 1001 1101 1 Set Q0 = 1 Q: Quotient = 00102 = +210
0001 0010 1101 Shift Left A,Q A: Remainder = 00012 = +110
1110 0010 1101 A ← A + M; MSB(A) = 1
0001 0010 1101 0 Restore Previous A ; Set Q0 = 0

CIS 1102 – ITC


SIGNED BINARY DIVISION: PRACTICE

Given:
W = (+6)10
X = (- 3)10

Task:
Find the quotient and remainder of dividing W by X using the procedure
of performing division with negative numbers.
• Express the dividend in 8 bits (load to A & Q)
• Express the divisor in 4 bits (load 2’s complement of +X to M)
• Show the sequence of events of the operation
• Express the final answer in binary and decimal forms

CIS 1102 – ITC


CIS 1102
INTRODUCTION TO COMPUTING

*** END ***

THANK YOU!

You might also like