Q. Write a function that receives an octal number and prints the equivalent number in other number bases i.e., in decimal, binary and hexadecimal equivalents.
Answer :-
def oct2others (n) : print("Passed octal number : ", n) numString = str(n) decNum = int(numString, 8) print("Number in Decimal: ", decNum) print("Number in Binary:", bin(decNum)) print("Number in Hexadecimal : ", hex(decNum)) num = int(input ("Enter an octal number :")) oct2others (num)
Please recall that bin() and hex( ) do not return numbers but return the string-representations of equivalent numbers in binary and hexadecimal number systems respectively.
Output :-
Enter an octal number :12345
Passed octal number : 12345
Number in Decimal: 5349
Number in Binary: 0b1010011100101
Number in Hexadecimal : 0x14e5
>>>
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )