Non-decimal radices/Convert: Difference between revisions
Content added Content deleted
(→{{header|Icon}} and {{header|Unicon}}: formatting) |
(→{{header|Icon}} and {{header|Unicon}}: commentary) |
||
Line 645: | Line 645: | ||
=={{header|Icon}} and {{header|Unicon}}== |
=={{header|Icon}} and {{header|Unicon}}== |
||
Icon and Unicon natively take integers in radix form for bases 2 through 36. There is no need to convert to integer as the value will be coerced when needed. However, a conversion routine is needed to convert integers back into radix form. |
|||
<lang Icon>procedure main() |
<lang Icon>procedure main() |
||
every ( ns := "16r5a" | "-12r1a" ) & |
every ( ns := "16r5a" | "-12r1a" ) & |
||
Line 655: | Line 657: | ||
link printf |
link printf |
||
procedure convert(i,b) #: convert i to base b |
procedure convert(i,b) #: convert i to base b radix representation |
||
static digits |
static digits |
||
initial digits := &digits || &lcase |
initial digits := &digits || &lcase |
||
Line 674: | Line 676: | ||
{{libheader|Icon Programming Library}} |
{{libheader|Icon Programming Library}} |
||
[http://www.cs.arizona.edu/icon/library/src/procs/printf.icn printf.icn provides printf] |
[http://www.cs.arizona.edu/icon/library/src/procs/printf.icn printf.icn provides printf] |
||
There are several conversion routines for bases in the IPL, however, none returns the input radix form. |
|||
Output:<pre>ns=16r5a -> n=90 -> 8r132 |
Output:<pre>ns=16r5a -> n=90 -> 8r132 |