Python  1.0
Functions
_01e_multbin Namespace Reference

Multiplication using shifts. More...

Functions

def Product (a, b)
 Multiplies two integers by using only the + operation. More...
 
def Product2 (a, b, base=10)
 
def main (argv=None)
 

Detailed Description

Multiplication using shifts.

Thinking binary:

       1011 X         11
       1101           13
       ----     --------
       1011 +   1*1*1011  1011 << 0
      00000     0*2*1011  0000 << 1
     101100     1*4*1011  1011 << 2
    1011000     1*8*1011  1011 << 3
    -------     --------
   10001111          143
   
Author
Paulo Roma
Since
15/10/2011

Function Documentation

◆ main()

def _01e_multbin.main (   argv = None)

◆ Product()

def _01e_multbin.Product (   a,
  b 
)

Multiplies two integers by using only the + operation.

Parameters
afirst factor.
bsecond factor.
Returns
a*b

Referenced by main().

◆ Product2()

def _01e_multbin.Product2 (   a,
  b,
  base = 10 
)
Equivalent version, but very inneficient.

Referenced by main().