- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddBinary.py
More file actions
Latest commit
37 lines (31 loc) · 473 Bytes
/
Copy pathAddBinary.py
File metadata and controls
37 lines (31 loc) · 473 Bytes
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
a="0"
b=""
la=len(a)
lb=len(b)
limit=la
ifla>=lb:
s='0'*(la-lb)
b=s+b
limit=la
else:
s='0'*(lb-la)
a=s+a
limit=lb
carry=0
res=''
foriinreversed(range(0,limit)):
tmp=carry+int(a[i]) +int(b[i])
iftmp==0:
res='0'+res
eliftmp==1:
res='1'+res
carry=0
eliftmp==2:
res='0'+res
carry=1
else:
res='1'+res
carry=1
ifcarry==1:
res='1'+res
print (res)