PY
py
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
''' using format(),bin()
def dectobcd(n):
return ''.join(format(int(c),'04b') for c in str(n))
def dectobin(n,m=1,r=''):
return bin(n)[2:]
'''
def dectobcd(n,r=''):
d=['0000','0001','0010','0011','0100',
'0101','0110','0111','1000','1001']
for c in str(n):
r=r+d[int(c)]
return r
def dectobin(n,m=1,r=''):
while n>=2**m:
m+=1
while m>0:
if n<2**(m-1):
r=r+'0'
else:
r=r+'1'
n=n-2**(m-1)
m-=1
return r
limit=int(input())
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run