Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a function that inputs a hexadecimal value, computes the equivalent binary

ID: 3620227 • Letter: W

Question

Write a function that inputs a hexadecimal value, computes the equivalent binary number by the replacement method, and prints the equivalent binary number. (All numbers should be positive.)

>>> from16to2()
Input hexadecimal value to convert: 1EA
000111101010

Note:
- Use the replacement method. Set up two strings "0123456789ABCDEF" and "0000000100100011010001010110011110001001101010111100110111101111" containing all values from 010 to 1510 in hexadecimal and binary, respectively. For each hexit (hexadecimal digit), find its position in the hexadecimal values string, then grab the corresponding 4 values in the binary values string.


There is another way this could be done, which you are not allowed to do: The replace() function could be used, replacing "1" with "0001", etc, resulting in 16 calls to the replace() function. You are not allowed to do this because:
- It would defeat the purpose of this exercise.
- It is a significantly inferior solution - it is not nearly as efficient.

Can someone help me write a code?

Explanation / Answer

Don't know anything about Python but you can set up a table with corresponding values 1 = 0001 2 = 0010 A = 1010 B = 1011 E = 1110 etc. for all of the possible values Then just select the appropriate items and load them from left to right in whatever is convenient in Python (register, subfields, whatever) In the above example you have 0001 - 1110 - 1010 (of course you don't want the dashes)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote