Python Function - Converts an Decimal Number to its equivalent numbers in binary, octal & hexadecimal

#Convert a decimal number to binary, octal and hexadecimal number
#using built in functions

def Dec2Others(num):
    print()
    bnum=bin(num)
    onum=oct(num)
    hnum=hex(num)
    print("Decimal Number      : ",num)
    print("Binary Number       : ",bnum)
    print("Octal Number        : ",onum)
    print("Hexa Decimal Number : ",hnum)

n=int(input("Enter a decimal number: "))
Dec2Others(n)





Output:


Enter a decimal number: 255

Decimal Number      :  255
Binary Number       :  0b11111111
Octal Number        :  0o377
Hexa Decimal Number :  0xff



No comments

Post your comments

Powered by Blogger.