def BitAdd(m, n, length):
    """Return m+n in string.
    
    Arguments:
    m -- Binary number in string
    n -- Same as above
    length -- The length of returned number (overflowed bit will be ignored)

    Returns: string
    """

    lmax = max(len(m), len(n))
    c = 0
    ml = [0] * (lmax - len(m)) + [int(x) for x in list(m)]
    nl = [0] * (lmax - len(n)) + [int(x) for x in list(n)]
    rl = []
    for i in range(1, lmax+1):
        if ml[-i] + nl[-i] + c == 0:
            rl.insert(0, 0)
            c = 0
        elif ml[-i] + nl[-i] + c == 1:
            rl.insert(0, 1)
            c = 0
        elif ml[-i] + nl[-i] + c == 2:
            rl.insert(0, 0)
            c = 1
        elif ml[-i] + nl[-i] + c == 3:
            rl.insert(0, 1)
            c = 1
    if c == 1:
        rl.insert(0, 1)
    if length > len(rl):
        rl = [0] * (length - len(rl)) + rl
    else:
        rl = rl[-length:]
    rl = "".join([str(x) for x in rl])
    return rl


def TwoComp(n):
    """Return the two's complement of given number.

    Arguments:
    n -- Binary number in string

    Returns: string
    """

    l = list(n)
    for i in range(len(l)):
        l[i] = "0" if l[i] == "1" else "1"
    return BitAdd("".join(l), "1", len(l))


def BitShift(n, shift):
    """Shift the bits rightward in arithmetical method.

    Arguments:
    n -- Binary number in string
    shift -- Number of times to shift

    Returns: string
    """

    if n[0] == "0":
        n_ = "".join(["0"] * shift) + n
    else:
        n_ = "".join(["1"] * shift) + n
    return n_[:len(n)]


def CalcBoothRecoding(n):
    """Calculate the Booth recoding number of given n.

    Arguments:
    n -- Binary number to calculate in string

    Returns: string

    Attention:
    "2" in returned string represents "1-hat".
    """

    n_ = [int(x) for x in list(n + "0")]
    r = []
    for i in range(len(n)):
        x = n_[i+1] - n_[i]
        if x == -1: r.append(2)
        else:       r.append(x)
    return "".join([str(x) for x in r])


def GenZeroStr(n):
    """Generate a bunch of zeroes.

    Arguments:
    n -- Number of zeroes

    Returns: string
    """

    return "".join(["0"] * n)
@@ -1327,16 +1327,71 @@
  method.
+%0A    If shift is negative, it shifts the bits leftward.
 %0A%0A    Ar
@@ -1496,24 +1496,65 @@
 ng%0A    %22%22%22%0A%0A
+    if shift %3E 0:       #Right shift%0A    
     if n%5B0%5D 
@@ -1561,16 +1561,20 @@
 == %220%22:%0A
+    
         
@@ -1601,24 +1601,28 @@
  shift) + n%0A
+    
     else:%0A  
@@ -1619,32 +1619,36 @@
   else:%0A        
+   
+ 
 n_ = %22%22.join(%5B%221
@@ -1659,24 +1659,28 @@
  shift) + n%0A
+    
     return n
@@ -1690,16 +1690,97 @@
 len(n)%5D%0A
+    else:%0A        n_ = n + %22%22.join(%5B%220%22%5D * (-shift))%0A        return n_%5B-len(n):%5D%0A
 %0A%0Adef Ca

make left-shiftable