# Function to convert decimal to binary
def decimalToBinary(num):
if num > 1:
decimalToBinary(num // 2)
print(num % 2, end='')
# Input from the user
number = int(input("Enter the decimal number: "))
# Main function call
decimalToBinary(number)
Enter the decimal number: 25
11001
bin()
, to simplify the process of converting a decimal number to binary. The bin()
function returns the binary string prefixed with 0b
.# Using built-in function
number = int(input("Enter the decimal number: "))
print("Binary Number:", bin(number)[2:])
Enter the decimal number: 56
Binary Number: 111000
Feature | User-Defined Function | Built-In Function |
---|---|---|
Complexity | Requires manual implementation | Simplifies the process |
Output Customization | Fully customizable | Requires slicing for clean output |
Use Case | Educational purposes | Quick conversions |