So here's the thing, I want to convert a base 10 integer and output it in base 16 as a string-
Here's what I have:
When I run the program, I get some weird output.
Where am I going wrong?
Plz help.
Thanks.
Here's what I have:
Code:
#number n in base ten to base b=16
def d(n,b):
ans=" "
quotient=n/b
while quotient !=0:
remainder=(quotient % b)
if remainder < 10:
ans= str(remainder) + ans
elif remainder == 10:
ans= 'A' + ans
elif remainder == 11:
ans= 'B' + ans
elif remainder == 12:
ans= 'C' + ans
elif remainder == 13:
ans= 'D' + ans
elif remainder == 14:
ans= 'E' + ans
elif remainder == 15:
ans= 'F' + ans
quotient=(quotient / b)
return str(ans)
print(d(200,16))
print(d(689,16))
Where am I going wrong?
Plz help.
Thanks.