-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathNon Restoring Division.py
More file actions
41 lines (31 loc) · 1.01 KB
/
Non Restoring Division.py
File metadata and controls
41 lines (31 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from Utils import Dec, Add, divInput, LeftShift
def main():
num1, num2, Q_bin, M_bin, M_bar_plus_one, A, SC = divInput()
for i in range(SC - 1):
print("Cycle:", i + 1)
print(f" A = {A} {Q_bin} ")
A, Q_bin = LeftShift(A, Q_bin)
print(f" Left Shift = {A} {Q_bin} ")
if A[0] == "1":
A = Add(A, M_bin, SC)
print(f" Add +{M_bin}")
else:
A = Add(A, M_bar_plus_one, SC)
print(f" Subtract +{M_bar_plus_one}")
if A[0] == "1":
Q_bin = Q_bin[:-1] + "0"
else:
Q_bin = Q_bin[:-1] + "1"
print(f" A = {A} {Q_bin} ")
print()
print()
if A[0] == "1":
print(f" Add +{M_bin}")
A = Add(A, M_bin, SC)
print(f" A = {A} {Q_bin} ")
quotient = Dec(Q_bin)
remainder = Dec(A)
print(f"{num1}/{num2}")
print(f"Quotient = {quotient}, Remainder = {remainder}")
if __name__ == '__main__':
main()