Site icon T4Tutorials.com

How to convert binary to decimal in Python

Write a Python program to convert the Decimal Number into binary.

Decimal to binary C++

# Defining the function to convert Decimal Number to binary  
def Decimal_2_binary(T4Tutorials):  
    Decimal_Number = int(T4Tutorials)  
    
    # Displaying the equivalent Decimal_Number  
    print ("The given Decimal number", Decimal_Number, "in Binary number is: ", bin(Decimal_Number))  
# we will define the function to convert Decimal_Number to octal  
def Decimal_2_octal(T4Tutorials):  
    Decimal_Number = int(T4Tutorials)  
    
    # Then, print the equivalent Decimal_Number  
    print ("The given Decimal number", Decimal_Number, "in Octal number is: ", oct(Decimal_Number))  
# we will define the function to convert Decimal_Number to hexaDecimal_Number  
def Decimal_2_hexaDecimal(T4Tutorials):  
    Decimal_Number = int(T4Tutorials)  
    
    # Then, print the equivalent Decimal_Number  
    print ("The given Decimal number", Decimal_Number, " in HexaDecimal_Number number is: ", hex(Decimal_Number))  
    
# Driver program  
T4Tutorials = int (input (" Please! Enter the Decimal_Number Number: "))  
Decimal_2_binary(T4Tutorials)  
Decimal_2_octal(T4Tutorials)  
Decimal_2_hexaDecimal(T4Tutorials)

Output

Please! Enter the Decimal Number: 19
The given Decimal number 19 in Binary number is: 0b10011
The given Decimal number 19 in Octal number is: 0o23
The given Decimal number 19 in HexaDecimal_Number number is: 0x13

Exit mobile version