Non-decimal radices/Convert: Difference between revisions
Content added Content deleted
(Added Easylang) |
|||
Line 1,353: | Line 1,353: | ||
=={{header|EasyLang}}== |
=={{header|EasyLang}}== |
||
<syntaxhighlight> |
<syntaxhighlight> |
||
func$ |
func$ num2str n base . |
||
if n = 0 |
if n = 0 |
||
return "0" |
return "0" |
||
. |
. |
||
d = n mod |
d = n mod base |
||
if d > 9 |
if d > 9 |
||
d += 39 |
d += 39 |
||
. |
. |
||
d$ = strchar (d + 48) |
d$ = strchar (d + 48) |
||
if n < |
if n < base |
||
return d$ |
return d$ |
||
. |
. |
||
return |
return num2str (n div base) base & d$ |
||
. |
. |
||
func |
func str2num s$ base . |
||
r = 0 |
r = 0 |
||
for c$ in strchars s$ |
for c$ in strchars s$ |
||
Line 1,374: | Line 1,374: | ||
d -= 39 |
d -= 39 |
||
. |
. |
||
r = r * |
r = r * base + d |
||
. |
. |
||
return r |
return r |
||
. |
. |
||
print |
print num2str 253 16 |
||
print |
print str2num "fd" 16 |
||
print |
print num2str 0 16 |
||
</syntaxhighlight> |
</syntaxhighlight> |
||