예제 #1
0
def booths(m,r):
	x=len(bin(m))
	y=len(bin(r))
	totallength = x+y+1

	if m<0 and r<0 or r<0:
		bugbit = 1
	else:
		bugbit = 0

	A = BitArray(int = m,length = totallength) << (y+1)
	compliment = BitArray(int = -m,length = totallength) << (y+1)
	P = BitArray(int = r, length = totallength) 
	P = P<<1

	for i in range(1,y+1):
		if P[-2:]=='0b01':
			P = BitArray(int = P.int + A.int, length = totallength)
		elif P[-2:]=='0b10':
			P = BitArray(int = P.int + compliment.int, length = totallength)
		P = BitArray(int = P.int>>1, length = totallength)

	P = P[:-1]

	P.int = P.int + bugbit
	steps =""
	return '<h1>RESULT</h1><br>'+steps+'<br><h3>decimal value: '+str(P.int)+'</br><br> binary value: '+str(P.bin)+"</h3>"
예제 #2
0
파일: booths.py 프로젝트: akhilari7/Cl3
def booth(m,r):
	 x = len(bin(m))
	 y = len(bin(r))
	 #after both numbers are negative, for some reason, the answer is one less than whats expected.
	 if m < 0 and r < 0 or r < 0 :
	 	bugbit = 1
	 else:
		bugbit = 0
	 totalLength = x+y + 1
	 A = BitArray(int = m, length = totalLength) << (y+1)
	 compliment = BitArray(int = -m, length = totalLength) << (y+1)
	 P = BitArray(int = r, length = totalLength)
	 P = P << 1
	 for i in range(1,y+1):
	 	if P[-2:] == '0b01':
	 		P = BitArray(int = P.int + A.int, length = totalLength)
	 	elif P[-2:] == '0b10':
	 		P = BitArray(int = P.int +compliment.int, length = totalLength)
	 	P = BitArray(int=P.int >> 1,length=totalLength)
	 P = P[:-1]
	 P.int = P.int + bugbit
	 return '<h1>RESULT</h1><br><h3>decimal value: '+str(P.int)+'</br><br> binary value: '+str(P.bin)
예제 #3
0
파일: booths.py 프로젝트: akhilari7/Cl3
def booth(m, r):
    x = len(bin(m))
    y = len(bin(r))
    #after both numbers are negative, for some reason, the answer is one less than whats expected.
    if m < 0 and r < 0 or r < 0:
        bugbit = 1
    else:
        bugbit = 0
    totalLength = x + y + 1
    A = BitArray(int=m, length=totalLength) << (y + 1)
    compliment = BitArray(int=-m, length=totalLength) << (y + 1)
    P = BitArray(int=r, length=totalLength)
    P = P << 1
    for i in range(1, y + 1):
        if P[-2:] == '0b01':
            P = BitArray(int=P.int + A.int, length=totalLength)
        elif P[-2:] == '0b10':
            P = BitArray(int=P.int + compliment.int, length=totalLength)
        P = BitArray(int=P.int >> 1, length=totalLength)
    P = P[:-1]
    P.int = P.int + bugbit
    return '<h1>RESULT</h1><br><h3>decimal value: ' + str(
        P.int) + '</br><br> binary value: ' + str(P.bin)
예제 #4
0
def booth(m, r):
    x = len(bin(m))
    y = len(bin(r))

    if m < 0 and r < 0 or r < 0:
        bugbit = 1
    else:
        bugbit = 0
    totalLength = x + y + 1
    A = BitArray(int=m, length=totalLength) << (y + 1)
    compliment = BitArray(int=-m, length=totalLength) << (y + 1)
    P = BitArray(int=r, length=totalLength)
    P = P << 1
    for i in range(1, y + 1):
        if P[-2:] == '0b01':
            P = BitArray(int=P.int + A.int, length=totalLength)
        elif P[-2:] == '0b10':
            P = BitArray(int=P.int + compliment.int, length=totalLength)
        P = BitArray(int=P.int >> 1, length=totalLength)
    P = P[:-1]
    P.int = P.int + bugbit
    return '<h1>RESULT</h1><br><h3>decimal value: ' + str(
        P.int) + '</br><br> binary value: ' + str(P.bin)
예제 #5
0
파일: booth.py 프로젝트: niranjanadsul/Cl3
def booth(a, b):
    #a multiplicand
    #b multiplier
    #calculate count of bits in multiplier
    count = bitcal(b)
    print "count ", count
    mA = BitArray(uint=a, length=8)  #multiplicand
    print "Multiplicand is "
    print mA.bin
    '''
	mAA=BitArray(uint=-a,length=8)
	print mAA.int
	print mAA.bin
	'''
    mB = BitArray(uint=b, length=8)  #multiplier
    print "Multiplier is "
    print mB.bin

    AC = BitArray(uint=0, length=8)
    QR = mB
    Q1 = BitArray(uint=0, length=1)
    Q2 = Q1
    print AC.bin, " ", QR.bin, " ", Q1.bin
    print ""
    for i in range(0, 8):
        if QR[7] == Q1[0]:
            #print "hi"
            Q1[0] = QR[7]
            QR = QR >> 1
            QR[0] = AC[7]
            Q2[0] = AC[0]
            AC = AC >> 1
            AC[0] = Q2[0]
            print AC.bin, " ", QR.bin, " ", Q1.bin, " Right shift"
        elif QR[7] > Q1[0]:
            AC.int = AC.int - mA.int
            print AC.bin, " ", QR.bin, " ", Q1.bin, " AC-M"
            Q1[0] = QR[7]
            QR = QR >> 1
            QR[0] = AC[7]
            Q2[0] = AC[0]
            AC = AC >> 1
            AC[0] = Q2[0]
            print AC.bin, " ", QR.bin, " ", Q1.bin, " right shift"
        elif QR[7] < Q1[0]:
            A = AC.int + mA.int
            AC = BitArray(uint=A, length=8)
            print AC.bin, " ", QR.bin, " ", Q1.bin, " AC+M"
            Q1[0] = QR[7]
            QR = QR >> 1
            QR[0] = AC[7]
            Q2[0] = AC[0]
            AC = AC >> 1
            AC[0] = Q2[0]
            print AC.bin, " ", QR.bin, " ", Q1.bin, " right shift"

    AC = AC + QR
    #print AC.bin
    product = AC.int
    #print "product"
    #print product
    return product, AC.bin
예제 #6
0
def incr_pass(board):
    new_pass = pass_count(board) + 1
    start = 2 * area + 8
    a = BitArray('0b00000000')
    a.int = new_pass
    board[start:start + 8] = a
예제 #7
0
def incr_turn(board):
    new_turn = (turn_count(board)) % 2 + 1
    start = 2 * area
    a = BitArray('0b00000000')
    a.int = new_turn
    board[start:start + 8] = a
예제 #8
0
def incr_pass(board):
    new_pass = pass_count(board) + 1
    start = 2 * area + 8
    a = BitArray('0b00000000')
    a.int = new_pass
    board[start:start + 8] = a
예제 #9
0
def incr_turn(board):
    new_turn = (turn_count(board)) % 2 + 1
    start = 2 * area
    a = BitArray('0b00000000')
    a.int = new_turn
    board[start:start + 8] = a