Non-decimal radices/Convert: Difference between revisions

Line 645:
 
=={{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()
every ( ns := "16r5a" | "-12r1a" ) &
Line 655 ⟶ 657:
link printf
 
procedure convert(i,b) #: convert i to base b radix representation
static digits
initial digits := &digits || &lcase
Line 674 ⟶ 676:
{{libheader|Icon Programming Library}}
[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
Anonymous user