Briefly explain bitwise multiplication

Systems Architecture
7th Edition
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Stephen D. Burd
Chapter8: Data And Network Communication Technology
Section: Chapter Questions
Problem 34VE
icon
Related questions
Question

Briefly explain bitwise multiplication

Expert Solution
Step 1

Bitwise multiplication can be done in 2 methods

1. left shift operator: In this the number is represented in binary and the multiplication is done by powers of 2 obtained using left shift operator

2. using Russian Peasant Algorithm: The idea is to double greater number and halve the lesser number until the lesser number becomes odd. Then add it to the first.

The program is written in python

 

Step 2

def russianPeasant(a, b): 
  
    res = 0 

    while (b > 0): 
        if (b & 1): 
            res = res + a 
        a = a << 1
        b = b >> 1
      
    return res 
  
print(russianPeasant(18, 8)) 

 

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer