Develop a python program to convert binary to decimal, octal to hexadecimal using functions.
Program:-
def binary_to_decimal(binary_num): decimal_num = int(binary_num, 2) return decimal_num def octal_to_hexadecimal(octal_num): decimal_num = int(octal_num, 8) hexadecimal_num = hex(decimal_num).replace('0x', '') return hexadecimal_num.upper() # Convert binary to decimal binary_num = input("Enter a binary number: ") decimal_num = binary_to_decimal(binary_num) print("Decimal equivalent:", decimal_num) # Convert octal to hexadecimal octal_num = input("Enter an octal number: ") hexadecimal_num = octal_to_hexadecimal(octal_num) print("Hexadecimal equivalent:", hexadecimal_num)
Output:-
Enter a binary number : 10111001
185
Enter a octal number : 675
1BD