Non-decimal radices/Convert: Difference between revisions
Content added Content deleted
m (update for julia 1+) |
Drkameleon (talk | contribs) (Added Arturo implementation) |
||
Line 412: | Line 412: | ||
<lang AppleScript>{{{binary:"11111111", octal:"377", hex:"ff"}, {upperHex:"FF", dgDecimal:"२५५"}}, |
<lang AppleScript>{{{binary:"11111111", octal:"377", hex:"ff"}, {upperHex:"FF", dgDecimal:"२५५"}}, |
||
{{binary:"11110000", octal:"360", hex:"f0"}, {upperHex:"F0", dgDecimal:"२४०"}}}</lang> |
{{binary:"11110000", octal:"360", hex:"f0"}, {upperHex:"F0", dgDecimal:"२४०"}}}</lang> |
||
=={{header|Arturo}}== |
|||
<lang rebol>fromBase: function [x,base][ |
|||
if base=2 [ return from.binary x ] |
|||
if base=8 [ return from.octal x ] |
|||
if base=16 [ return from.hex x ] |
|||
return to :integer x |
|||
] |
|||
toBase: function [x,base][ |
|||
if base=2 [ return as.binary x ] |
|||
if base=8 [ return as.octal x ] |
|||
if base=16 [ return as.hex x ] |
|||
return to :string x |
|||
] |
|||
loop 1..20 'i -> |
|||
print [ |
|||
i "base2:" toBase i 2 "base8:" toBase i 8 "base16:" toBase i 16 |
|||
] |
|||
print "" |
|||
print ["101 => from base2:" fromBase "101" 2 "from base8:" fromBase "101" 8 "from base16:" fromBase "101" 16] |
|||
print ["123 => from base8:" fromBase "123" 8 "from base16:" fromBase "123" 16] |
|||
print ["456 => from base8:" fromBase "456" 8 "from base16:" fromBase "456" 16]</lang> |
|||
{{out}} |
|||
<pre>1 base2: 1 base8: 1 base16: 1 |
|||
2 base2: 10 base8: 2 base16: 2 |
|||
3 base2: 11 base8: 3 base16: 3 |
|||
4 base2: 100 base8: 4 base16: 4 |
|||
5 base2: 101 base8: 5 base16: 5 |
|||
6 base2: 110 base8: 6 base16: 6 |
|||
7 base2: 111 base8: 7 base16: 7 |
|||
8 base2: 1000 base8: 10 base16: 8 |
|||
9 base2: 1001 base8: 11 base16: 9 |
|||
10 base2: 1010 base8: 12 base16: a |
|||
11 base2: 1011 base8: 13 base16: b |
|||
12 base2: 1100 base8: 14 base16: c |
|||
13 base2: 1101 base8: 15 base16: d |
|||
14 base2: 1110 base8: 16 base16: e |
|||
15 base2: 1111 base8: 17 base16: f |
|||
16 base2: 10000 base8: 20 base16: 10 |
|||
17 base2: 10001 base8: 21 base16: 11 |
|||
18 base2: 10010 base8: 22 base16: 12 |
|||
19 base2: 10011 base8: 23 base16: 13 |
|||
20 base2: 10100 base8: 24 base16: 14 |
|||
101 => from base2: 5 from base8: 65 from base16: 257 |
|||
123 => from base8: 83 from base16: 291 |
|||
456 => from base8: 302 from base16: 1110</pre> |
|||
=={{header|AutoHotkey}}== |
=={{header|AutoHotkey}}== |