Question
The hexademical number system uses base 16 with digits 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F.
The hexademical number system uses base 16 with digits 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F. Hexadecimal is often used in computer systems programming. Write a Python program, in a file called convertHex.py, to request a decimal number from the user and output the hexadecimal value. To compute the hexadecimal value we have to find the hexadecimal digits hn, hn-1, hn-2, ..., h2, h1, and h0, such that
d = hn x 16n + hn-1 x 16n-1 + hn-2 x 16n-2 + ... + h2 x 162 + h1 x 161 + h0 x 160
These hexadecimal digits can be found by successively dividing d by 16 until the quotient is 0; the remainders are h0, h1, ..., hn-1, hn.
For example, if d=589:
- 589/16 is 36 with a remainder of 13 - 13 in hexadecimal is 'D' - this is h0
- 36/16 is 2 with a remainder of 4 - 4 in hexadecimal is '4' - this is h1
- 2/16 is 0 with a remainder of 2 - 2 in hexadecimal is '2' - this is h2
So 589 in decimal is 24D in hexadecimal.
Your program should include the following functions:
- decToHex(dec_value) - returns the hexadecimal equivalent of dec_value (as a string)
- getHexChar(dec_digit) - returns the hexadecimal digit for dec_digit (note that 10 in decimal is 'A' in hex, 11 in decimal is 'B', etc)
Sample output:
Enter decimal value: 589 589 is equal to 24D in hexadecimal
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started