How would you recursively or iteratively change a decimal to hexadecimal?
I wrote a sample program that does not really work:
def ChangeHex(n):
if (n < 0):
print(0)
elif (n<=1):
print(n)
else:
ChangeHex(n / 16)
if (n == 15):
print("F")
if (n == 14):
print("E")
if (n == 13):
print("D")
if (n == 12):
print("C")
if (n == 11):
print("B")
if (n == 10):
print("A")
n % 16
How would I make it work properly? I know there is a built in function but I want to do it this way.
1 Answer