Non-decimal radices/Convert: Difference between revisions

no edit summary
(Added Easylang)
No edit summary
 
(2 intermediate revisions by 2 users not shown)
Line 1,353:
=={{header|EasyLang}}==
<syntaxhighlight>
func$ n2snum2str n bbase .
if n = 0
return "0"
.
d = n mod bbase
if d > 9
d += 39
.
d$ = strchar (d + 48)
if n < bbase
return d$
.
return n2snum2str (n div bbase) bbase & d$
.
func s2nstr2num s$ bbase .
r = 0
for c$ in strchars s$
Line 1,374:
d -= 39
.
r = r * bbase + d
.
return r
.
print n2snum2str 253 16
print s2nstr2num "fd" 16
print n2snum2str 0 16
</syntaxhighlight>
 
Line 3,259:
$num.base($base);
}</syntaxhighlight>
These work on any real type including integer types. There is also a build in method/function for Strings: [https://docs.raku.org/routine/parse-base parse-base].
 
=={{header|REXX}}==
3

edits