Prompt the user to choose the type of conversion to perform: • Enter 1, to convert from decimal to hex • Enter 2, to convert from hex to decimal • For input values other than 1 or 2, prompt the user again to input a valid value. Create a recursive function named hexToDecimal() that takes in a hexadecimal value and returns the equivalent decimal number. Create another recursive function named decimalToHex () that takes in a decimal value and returns the equivalent hexadecimal number.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

how do you code a recursive function that converts hex to decimal and decimal to hex in python 3? without using the built-in python functions that convert directly from integer to hex and vice-versa like int() and hex()?

I'm having trouble setting up the parameters so please include notes/comments in your code.

Also, for checking if the input is valid, is my code correct? (please refer to the photo)

def is_valid_input(x):
    """Check if the input provided is valid"""
    if x!=1 or x!=2:
        return False
    return True

• Prompt the user to choose the type of conversion to perform:
• Enter 1, to convert from decimal to hex
• Enter 2, to convert from hex to decimal
• For input values other than 1 or 2, prompt the user again to input a valid value.
• Create a recursive function named hexToDecimal() that takes in a hexadecimal value and returns the
equivalent decimal number.
• Create another recursive function named decimalToHex () that takes in a decimal value and returns the
equivalent hexadecimal number.
Transcribed Image Text:• Prompt the user to choose the type of conversion to perform: • Enter 1, to convert from decimal to hex • Enter 2, to convert from hex to decimal • For input values other than 1 or 2, prompt the user again to input a valid value. • Create a recursive function named hexToDecimal() that takes in a hexadecimal value and returns the equivalent decimal number. • Create another recursive function named decimalToHex () that takes in a decimal value and returns the equivalent hexadecimal number.
Sample Input 0
1
15655185
Sample Output 0
Enter (1) to convert from decimal to hex, (2) to convert from hex to decimal: 1
Enter a decimal value: 15655185
The hexadecimal equivalent of 15655185 is EEE111.
Sample Input 1
2
EEE
Sample Output 1
Enter (1) to convert from decimal to hex, (2) to convert from hex to decimal: 2
Enter a hexadecimal value: EEE
The decimal equivalent of EEE is 3822.
Sample Input 2
0
1
47793
Sample Output 2
Enter (1) to convert from decimal to hex, (2) to convert from hex to decimal: 0
Invalid input.
Enter (1) to convert from decimal to hex, (2) to convert from hex to decimal: 1
Enter a decimal value: 47793
The hexadecimal equivalent of 47793 is BAB1.
Transcribed Image Text:Sample Input 0 1 15655185 Sample Output 0 Enter (1) to convert from decimal to hex, (2) to convert from hex to decimal: 1 Enter a decimal value: 15655185 The hexadecimal equivalent of 15655185 is EEE111. Sample Input 1 2 EEE Sample Output 1 Enter (1) to convert from decimal to hex, (2) to convert from hex to decimal: 2 Enter a hexadecimal value: EEE The decimal equivalent of EEE is 3822. Sample Input 2 0 1 47793 Sample Output 2 Enter (1) to convert from decimal to hex, (2) to convert from hex to decimal: 0 Invalid input. Enter (1) to convert from decimal to hex, (2) to convert from hex to decimal: 1 Enter a decimal value: 47793 The hexadecimal equivalent of 47793 is BAB1.
Expert Solution
steps

Step by step

Solved in 4 steps with 5 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education