Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 66832d2

Browse files
Updated script.py added comments
1 parent de5f7b2 commit 66832d2

File tree

1 file changed

+38
-12
lines changed

1 file changed

+38
-12
lines changed

‎Restoring Divider/script.py

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@ def main():
55
Q=bin(Q).replace("0b", "")
66
M=bin(M).replace("0b", "")
77
size=0
8-
8+
"""
9+
This part makes the initialisation of required for the Restoring Division to occur.
10+
Which includes:
11+
1) Setting an extra to M compared to A
12+
2) Filling up A with zeroes
13+
3) Setting the size
14+
"""
915
if len(M)==len(Q):
1016
M="0"+M
1117
else:
@@ -20,6 +26,9 @@ def main():
2026
for i in range (0,len(M),1):
2127
A="0"+A
2228
size=len(M)
29+
"""
30+
The Calculation and Line by Line Display begins from here
31+
"""
2332
A="0"+A
2433
M="0"+M
2534
M2=twos_complement(M)
@@ -30,40 +39,59 @@ def main():
3039
print("M2=",M2)
3140
printer="A\t\tQ\t\tSize\t\tSteps"
3241
print(printer)
33-
printer=A+"\t\t"+Q+"\t\t"+str(size)+"\t\tInitialization"
42+
printer=A+"\t\t"+Q+"\t\t"+str(size)+"\t\tInitialization"#Printing the Initialisation step
3443
print(printer)
35-
#print("A=",A)
36-
#print("Q=",Q)
37-
#print("size=",size)
38-
44+
"""
45+
The division will be taking place until the size of the Divisor becomes zero
46+
"""
3947
for i in range(size,0,-1):
40-
48+
"""
49+
Left Shift Operation
50+
"""
4151
A=A[1:len(A)]+Q[0]
4252
Q=Q[1:len(Q)]
4353
printer=A+"\t\t"+Q+"\t\t"+str(size)+"\t\tLeft Shift"
4454
print(printer)
55+
56+
"""
57+
Subtraction
58+
"""
4559
A=add(A,M2)
4660
printer=A+"\t\t"+Q+"\t\t"+str(size)+"\t\tSubtraction"
4761
print(printer)
62+
63+
"""
64+
Bit Checking and AAddition if required
65+
"""
4866
if A[0]=='0':
4967
Q=Q+"1"
5068
else:
5169
Q=Q+"0"
5270
A=add(A,M)
5371
printer=A+"\t\t"+Q+"\t\t"+str(size)+"\t\tBit Checking"
5472
print(printer)
73+
74+
"""
75+
Decreasing Size
76+
"""
5577
size=size-1
5678
printer=A+"\t\t"+Q+"\t\t"+str(size)
5779
print(printer)
5880

5981
def twos_complement(n):
6082
a=""
6183
c=""
84+
"""
85+
Performing 1's Complement by changing all zeroes to one
86+
"""
6287
for i in range(0,len(n)):
6388
if n[i]=='1':
6489
a=a+"0"
6590
else:
6691
a=a+"1"
92+
"""
93+
Performing 2's complement by adding 1 to the 1's complement
94+
"""
6795
d=""
6896
for i in range (0,len(a)-1):
6997
d=d+"0"
@@ -72,6 +100,9 @@ def twos_complement(n):
72100
return c
73101

74102
def add(x,y):
103+
"""
104+
Binary Adddition bing carried out
105+
"""
75106
carry=""
76107
result=""
77108
carry="0"
@@ -106,9 +137,4 @@ def add(x,y):
106137
result="0"+result
107138
carry='1'
108139
return result
109-
110-
def left_shift(A,Q):
111-
A=A[1:len(A)]+Q[0]
112-
Q=Q[1:len(Q)]
113-
114140
main()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /