I'm having trouble trying to create a function that converts positive decimal numbers into a hex string (without printing, just returning the string with hex number)
A function that converts binary to hex string should work to, if you think it's easier
I've already tried some codes I've found in the forum, but none of them worked properly, some just worked for numbers in the 0-15 interval and then started to print from 0 again.
def hex(n):
r = ''
if n < 16:
if n < 10: return r + str(n)
if n == 10: return r + 'A'
if n == 11: return r + 'B'
if n == 12: return r + 'C'
if n == 13: return r + 'D'
if n == 14: return r + 'E'
if n == 15: return r + 'F'
else:
hex(n//16)
Thats the code I've said that works just til dec 15
The code need to receive a decimal or a binary number (if it's easier), and return a string with number converted in hex.
Edit: I can't use hex() bin(), dec()...