maynul67

Decimal to Binary converter

Jul 10th, 2021
1,509
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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)
RAW Paste Data