Non-decimal radices/Convert: Difference between revisions

sort
(Added Ada)
(sort)
Line 63:
Put_line("1a (base 16) is decimal" & Integer'image(To_Decimal("1a", 16)));
end Number_Base_Conversion;</ada>
 
=={{header|Python}}==
<python>
def baseN(num,b):
return ((num == 0) and "0" ) or ( baseN(num // b, b).lstrip("0") + "0123456789abcdefghijklmnopqrstuvwxyz"[num % b])
k = 26
s = baseN(k,16) # returns the string 1a
i = int('1a',16) # returns the integer 26
</python>
 
=={{header|Java}}==
Line 89 ⟶ 80:
i = +('0x'+s) //hexadecimal base 16, if s='1a' then i=26.
</pre>
 
=={{header|Python}}==
<python>
def baseN(num,b):
return ((num == 0) and "0" ) or ( baseN(num // b, b).lstrip("0") + "0123456789abcdefghijklmnopqrstuvwxyz"[num % b])
k = 26
s = baseN(k,16) # returns the string 1a
i = int('1a',16) # returns the integer 26
</python>
Anonymous user