Non-decimal radices/Convert: Difference between revisions

Content added Content deleted
(J: elaborate, a bit)
Line 608: Line 608:


=={{header|J}}==
=={{header|J}}==
J supports direct specification of numbers by base, as in these examples:
J supports direct specification of integers by base. The numbers are expressed as the base to be used (using base 10), the letter b, followed by the number itself. Following the initial letter b, other (lower case) letters represent "digts" 10 (a) through 35 (z), as in these examples:
<lang j> 2b100 8b100 10b100 16b100 36b100 36bzy
<lang j> 2b100 8b100 10b_100 16b100 36b100 36bzy
4 64 100 256 1296 1294</lang>
4 64 _100 256 1296 1294</lang>

Programs for conversion of numeric values to literals, and of literals to numbers:
Additionally, J has primitives [http://www.jsoftware.com/help/dictionary/d401.htm #.] and [http://www.jsoftware.com/help/dictionary/d402.htm #:] for dealing with base conversion issues.

Here are programs for conversion of numeric values to literals, and of literals to numbers:
<lang j>numerals=: '0123456789abcdefghijklmnopqrstuvwxyz'
<lang j>numerals=: '0123456789abcdefghijklmnopqrstuvwxyz'
baseNtoL=: numerals {~ #.inv
baseNtoL=: numerals {~ #.inv