79. Python Program to Convert Decimal number into Binary number.
How does this program work?
- This program is used to convert given Decimal number into equivalent of Binary number using Python.
- That means convert number with base value 10 to base value 2.
- The integer entered by user will store in one variable. Divide that number by 2.
- Store the remainder when the number is divided by 2 in an array, Repeat the above step until the number is greater than zero.
Here is the code
def decimalToBinary(n):
if(n > 1):
decimalToBinary(n//2)
print(n%2, end=' ')
n = int(input( "Enter an integer number: "))
print("The equivalent Binary number is : ", end='')
decimalToBinary(n)