Advertisement
maynul67

Decimal to Binary converter

Jul 10th, 2021
1,669
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.23 KB | None | 0 0
  1. def dec_bin(n):
  2.     list = []
  3.     while n > 0:
  4.         list.append(n%2)
  5.         n = n//2
  6.     list.reverse()
  7.        
  8.     binary = ""
  9.     for bit in list:
  10.         binary += str(bit)
  11.     return binary
  12.  
  13. n = int(input("enter your decimal number:    "))
  14. binary = dec_bin(n)
  15. print(binary)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement