Non-decimal radices/Convert: Difference between revisions
Content added Content deleted
(Added Sidef entry) |
m (→{{header|Sidef}}: improved example) |
||
Line 2,200: | Line 2,200: | ||
{{trans|Perl}} |
{{trans|Perl}} |
||
<lang ruby>static to = [@|'0'..'9', @|'a'..'z'] |
<lang ruby>static to = [@|'0'..'9', @|'a'..'z'] |
||
static from |
static from = Hash(to.pairs.map{@|_}.flip...) |
||
func base_to(n, b) { |
func base_to(n, b) { |
||
Line 2,215: | Line 2,215: | ||
n.each { |c| t = (b*t + from{c}) } |
n.each { |c| t = (b*t + from{c}) } |
||
t |
t |
||
} |
|||
}</lang> |
|||
say base_from("rosetta", 36) # string to number |
|||
say base_to(60272032366, 36) # number to string</lang> |
|||
=={{header|Slate}}== |
=={{header|Slate}}== |