0% found this document useful (0 votes)
164 views9 pages

Booth Algorithm, Toom Cook, Restoring and Non Restoring, Karatsuba

The document provides solutions to multiplication and division problems using various algorithms. For multiplication, it uses the Karatsuba, Toom-Cook and Booth's algorithms to multiply two 6-digit, 9-digit and arbitrary size numbers respectively. For division, it uses the restoring and non-restoring division algorithms to divide an 8-bit number by a 6-bit number in both cases. Detailed step-by-step workings are shown for all problems.

Uploaded by

dileshwar
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)
164 views9 pages

Booth Algorithm, Toom Cook, Restoring and Non Restoring, Karatsuba

The document provides solutions to multiplication and division problems using various algorithms. For multiplication, it uses the Karatsuba, Toom-Cook and Booth's algorithms to multiply two 6-digit, 9-digit and arbitrary size numbers respectively. For division, it uses the restoring and non-restoring division algorithms to divide an 8-bit number by a 6-bit number in both cases. Detailed step-by-step workings are shown for all problems.

Uploaded by

dileshwar
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/ 9

Assignment Number.

Ques 1.

Multiply two 6 digit numbers using Karatsuba Algorithm.

Sol.1

Let the two numbers be x 200591 and y 160891,


Now splitting the numbers as follows

x as x1 200 , x2 591 and y as y1 160 , y2 891 .


Multiplying the two numbers as shown below
x y

(200000 591).(160000 891) (200 103 591).(160 103 891)

x y

(200 160 106 ) (591 891) (200 891103 ) (591160 103 )

x y

(200 160 106 ) (591 891) (200 891 591160)103

..(1)

According to Karatsuba Algorithm,


( x1 x2 )( y1 y2 ) x1 y1 x2 y2 ( x1 y2 x2 y1 )
( x1 y2 x2 y1 ) ( x1 x2 )( y1 y2 ) x1 y1 x2 y2

Rewriting equation (1) as per Karatsuba Algorithm


x y

(200 160 106 ) (591 891) (200 891 591160)103

x y

(200 160 106 ) (591 891) {(200 591)(160 891) (200 160) (891 591)}103

x y

(32000 106 ) (526581) 103 (831341 32000 526581)

x y

(32000000000 526581 272760000) 32273286581

x y

32273286581

Ans.

Ques 2.

Multiply two 9 digit numbers using Toom Cook Algorithm.

Sol.2

Let the two numbers be P 211111115 and Q 505050501 ,


Assuming value of b 102 ,
Step1: Splitting
We have , P 211111115 and Q 505050501
Select the base B = bi, such that the number of digits of both A and B in base B is atmost k
(e.g., 3 in Toom-3)
log P log Q

Here, i max b , b 1
k
k

log P log Q

log 211111115 logb 505050501

i max b , b 1 max b
,
1
k
k
k
k

4.15 4.35
i max
,
1 11 2
3 3

k 3 for TOOM 3

B b2 10000 .

We then separate P and Q into their base B digits pi and qi. .


p2 2 , p1 1111, p0 1115 and q2 5 , q2 0505 , q0 0501

Writing in polynomial form,


P( x) p2 x 2 p1 x p0 2 x 2 1111x 1115 and Q( x) q2 x2 q1 x q0 5x 2 0505x 0501

Step2: Evaluation
Now evaluating P( x) and Q( x) as follows, for points at (0,1, 1, 2, )
P(0)

1115

Q(0)

0501

P(1)

2228

Q(1)

1011

P(1) 6
P(2) 1099

Q(1) 1
Q(2) 489

P ( ) 2

Q () 5

Step3: Pointwise Multiplication


r (0)

P(0)Q(0)

558615

r (1)

P(1)Q(1)

2252508

r (1)
r (2)

P(1)Q(1)
P(2)Q(2)

6
537411

r ( )

P()Q()

10

Step4: Interpolation
Using the given below matrix for interpolation we get,

0
0
0
0 r (0)
r0 1
r 1/ 2 1/ 3 1 1/ 6 2 r (1)

r1 1 1/ 2 1/ 2
0
1 r (1)

r2 1/ 2 1/ 6 1/ 2 1/ 6 2 r (2)
r 0
0
0
0
1 r ()
r0

558615

r1
r1
r2

934016
567632
6547

10

Arranging above outputs according to base B = 10000 as shown below


5 5 8 6 1 5
9 3 4 0 1 6
5 6 7 6 3 2
6 5 4 7
1 0
1 0 6 6 0 3 7 7 2 5 4 0 7 1 8 6 1 5

Final Output P Q 1066077254071861

Ans.

Ques 3.

Multiply two numbers using Booths Algorithm.


(a) Let M = 10110110 ( -74 ) and Q = 01100010 ( 98 )
Applying Booths algorithm as shown below,

Sol.

Q -1

Operation

Cycle

00000000

01100010

10110110

Initial values

First`

00000000

00110001

10110110

Shift

01001010

00110001

10110110

A A-M

00100101

00011000

10110110

Shift

11011011

00011000

10110110

A A+M

11101101

10001100

10110110

Shift

11110110

11000110

10110110

Shift

Fourth

11111011

01100011

10110110

Shift

Fifth

01000101

01100011

10110110

A A-M

Sixth

00100010

10110001

10110110

Shift

00010001

01011000

10110110

Shift

Seventh

11000111

01011000

10110110

A A+M

Eighth

11100011

10101100

10110110

Shift

Second

Third

From the above table the output is combination of A and Q i.e,


AQ = (1110001110101100)2 = 7252
Multiplying M Q 74 98 7252

Ans.

(b) Let M = 10110101 ( -75 ) and Q = 10111100 ( - 68 )


Applying Booths algorithm as shown below,

Sol.

Q-1

Operation

Cycle

00000000

10111100

10110101

Initial values

First

00000000

01011110

10110101

Shift

00000000

00101111

10110101

Shift

Second

01001011

00101111

10110101

A A-M

Third

00100101

10010111

10110101

Shift

00010010

11001011

10110101

Shift

Fourth

00001001

01100101

10110101

Shift

Fifth

00000100

10110010

10110101

Shift

Sixth

10111001

10110010

10110101

A A-M

Seventh

11011100

11011001

10110101

Shift

00100111

11011001

10110101

A A-M

00010011

11101100

10110101

Shift

Eighth

From the above table the output is combination of A and Q i.e.,


AQ = (0001001111101100)2 = 5100
Multiplying M Q 75 68 5100

Ans.

Ques 4.
Sol.

Divide two numbers using Restoring Division Algorithm.


Taking dividend ( x ) as 8 bit number and divisor( d ) as 6 bit number.
Let x (136)10 (10001000)2 and y (34)10 (100010)2
Substitute A = x and P = initial value and B = y = 100010
2s complement of B = 011110
Applying Restoring Algorithm as shown below.

Operation

000000

10001000

Initial Values

000001

0001000_

Shift Left 1Bit

-100010

0001000_

Subtract B

-100001

00010000

(-ve) set LSB to 0

000001

00010000

restore

000010

0010000_

Shift

-100010

0010000_

Subtract

-100000

00100000

(-ve) set LSB to 0

0000010

00100000

restore

0000100

0100000_

Shift

-100010

0100000_

Subtract B

011110

01000000

(-ve) set LSB to 0

000100

01000000

restore

001000

1000000_

Shift

-100010

1000000_

Subtract

-011010

10000000

(-ve) set LSB to 0

001000

10000000

Restore

Cycle

First

Second

Third

Fourth

010001

0000000_

Shift

-100010

0000000_

Subtract

-010001

00000000

(-ve) set LSB to 0

010001

00000000

Restore

100010

0000000_

Shift

-100010

0000000_

Subtract

000000

00000001

(+ve) set LSB to 0

000000

0000001_

Shift

-100010

0000001_

Subtract

-100010

00000010

(-ve) set LSB to 0

000000

00000010

Restore

000000

0000010_

Shift

-100010

0000010_

Subtract

-100010

00000100

(-ve) set LSB to 0

000000

00000100

Restore

Fifth

Sixth

Seventh

Eighth

From the above table the output remainder is P and Quotient is A i.e,
P = (000000)2 = 0 = Remainder and A = (00000100)2 = 4 = Quotient
We get

136
4 as quotient and 0 as remainder.
34

Ans.

Ques 5.
Sol.

Divide two numbers using Non Restoring Division Algorithm.


Taking dividend ( x ) as 8 bit number and divisor( d ) as 6 bit number
Let x (200)10 (11001000)2 and y (40)10 (101000)2
Substitute A = x and P = initial value and B = y = 00101000
2s complement of B = 11011000
Applying Restoring Algorithm as shown below.

Operation

Cycle

00000000

11001000

Initial vaule

First

00000001

1001000_

Shift 1 bit left

11011000

1001000_

Subtract B

11011001

10010000

(-ve) set LSB to 0

10110011

0010000_

Shift

00101000

0010000_

Add B

11011011

00100000

(-ve) set LSB to 0

10110110

0100000_

Shift

00101000

0100000_

Add B

11011110

01000000

(-ve) set LSB to 0

10111100

1000000_

Shift

00101000

1000000_

Add B

11100100

10000000

(-ve) set LSB to 0

11001001

0000000_

Shift

00101000

0000000_

Add B

Second

Third

Fourth

Fifth

11110001

00000000

(-ve) set LSB to 0

11100010

0000000_

Shift

00101000

0000000_

Add B

00001010

00000001

(+ve) set LSB to 0

00010100

0000001_

Shift

11011000

0000001_

Add B

11101100

00000010

(-ve) set LSB to 0

11011000

0000010_

Shift

00101000

0000010_

Add B

00000000

00000101

(+ve) set LSB to 0

Sixth

Seventh

Eighth

From the above table the output remainder is P and Quotient is A. Here P is (+ve), therefore
previous value is not restored.
P = (000000)2 = 0 = Remainder and A = (00000101)2 = 5 = Quotient.
We get

200
5 as quotient and 0 as remainder
40

Ans.

You might also like