Friday, June 12, 2015

Conversion of decimal to hexadecimal, binary and octal in Python

#num= int(input("Enter a decimal number:))
num = 15
print "Decimal value of given number:", num

print "Octal value of", num, ":",oct(num)
print "Binary value of", num, ":",bin(num)
print "Hexadecimal value of", num, ":",hex(num)


Output:

Decimal value of given number: 15
Octal value of 15 : 017
Binary value of 15 : 0b1111
Hexadecimal value of 15 : 0xf

No comments:

Post a Comment