Embed presentation
Download to read offline
![2(b) Develop a python program to convert binary to decimal, octal to hexadecimal
using functions.
def BinToDec(b):
return int(b, 2)
print("Enter the Binary Number: ", end="")
bnum = input()
dnum = BinToDec(bnum)
print("nEquivalent Decimal Value = ", dnum)
def OctToHex(o):
return hex(int(o, 8))
print("Enter Octal Number: ", end="")
onum = input()
hnum = OctToHex(onum)
print("nEquivalent Hexadecimal Value =", hnum[2:].upper())](https://image.slidesharecdn.com/python-2b-231124062757-8c436273/85/python-2b-pdf-1-320.jpg)
The document provides code for two Python functions: one to convert a binary number to decimal, and another to convert an octal number to hexadecimal. The binary to decimal function takes a binary number as a string, converts it to an integer in base 2, and returns the decimal equivalent. The octal to hexadecimal function converts an octal number string to an integer in base 8, then returns the hexadecimal representation with a leading "0x". It is tested by prompting the user for input numbers and printing the results.
![2(b) Develop a python program to convert binary to decimal, octal to hexadecimal
using functions.
def BinToDec(b):
return int(b, 2)
print("Enter the Binary Number: ", end="")
bnum = input()
dnum = BinToDec(bnum)
print("nEquivalent Decimal Value = ", dnum)
def OctToHex(o):
return hex(int(o, 8))
print("Enter Octal Number: ", end="")
onum = input()
hnum = OctToHex(onum)
print("nEquivalent Hexadecimal Value =", hnum[2:].upper())](https://image.slidesharecdn.com/python-2b-231124062757-8c436273/85/python-2b-pdf-1-320.jpg)