0% found this document useful (0 votes)
5 views3 pages

Cao Expt 6

The document details an experiment conducted by Deepanshu Aggarwal on restoring division, including the problem statement and the corresponding Python program. The program takes dividend and divisor values, performs binary division, and outputs the accumulator, quotient, and remainder. The conclusion highlights the understanding gained from the experiment.

Uploaded by

Sumit Rathod
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)
5 views3 pages

Cao Expt 6

The document details an experiment conducted by Deepanshu Aggarwal on restoring division, including the problem statement and the corresponding Python program. The program takes dividend and divisor values, performs binary division, and outputs the accumulator, quotient, and remainder. The conclusion highlights the understanding gained from the experiment.

Uploaded by

Sumit Rathod
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/ 3

NAME: Deepanshu Aggarwal

UID: 2021300002

SUBJECT CAO

EXPERIMENT 6
NO :
DATE OF 2/11/22
PERFORMANCE
DATE OF 6/11/22
SUBMISSION
PROBLEM Make a program for restoring division
STATEMENT :
PROGRAM: q = int(input("Enter the dividend value: "))
m = int(input("Enter the divisor value: "))
cm = m

blen = 1 + len(bin(abs(q)))
m = bin(m)
m = (blen - len(m)) * '0' + m[2::]

a = (blen - 2) * '0'

q = bin(q)
q = q[2::]

count = len(q)

def comp_2(ib):
c = 1
ib2 = ""
ib = ib[::-1]
for n in range(len(ib)):
if ib[n] == '0' and c == 1:
c = 1
ib2 = ib2+'0'
elif ib[n] == '1' and c == 1:
c = 0
ib2 = ib2+'1'
elif ib[n] == '1' and c == 0:
ib2 = ib2+'0'
elif ib[n] == '0' and c == 0:
ib2 = ib2+'1'
return ib2[::-1]

def add(acc,adder):
i = len(acc)-1
c = 0
acc = list(acc)
adder = list(adder)
while i >= 0:
if (acc[i] == '0' and adder[i] == '1') or (acc[i] ==
'1' and adder[i] == '0'):
num = 1 + c
if num == 2:
acc[i] = '0'
elif num == 1:
acc[i] = '1'

elif acc[i] == '1' and adder[i] == '1':


num = 0 + c
if num == 1:
acc[i] = '1'
else:
c = 1
acc[i] = '0'

elif acc[i] == '0' and adder[i] == '0':


num = c
if num == 1:
c = 0
acc[i] = '1'
else:
acc[i] = '0'
i = i - 1
return "".join(acc)

def full():
global a
global m
global q
temp = q[0]
q = q[1:]
a = a[1:] + temp

cm = comp_2(bin(cm)[2::])
cm = (blen - len(cm) - 2) * '1' + cm

if __name__ == '__main__':
while count > 0:
full()
a = add(a, cm)
if a[0] == '1':
q = q[:] + '0'
a = add(a, m)
elif a[0] == '0':
q = q[:] + '1'
count = count - 1
print("Accumulator is: ", a)
print("Q is : ", q)
print("Remainder eq is : " + str(int(a, 2)))
print("Quotient eq is : " + str(int(q, 2)))

RESULT ( SNAPSHOT)

CONCLUSION: By performing this experiment, I understood the concept and


implementation of restoring division.

You might also like