This site is supported by donations to The OEIS Foundation.
Template:Digit as char
From OeisWiki
The following documentation is located at Template:Digit as char/doc. [<Edit> Template:Digit as char/doc]
[⧼Purge⧽ Template:Digit as char]
[⧼Purge⧽ Template:Digit as char]
The {{digit as char}} base conversion template converts a given digit (as integer) into the 0-indexed character (with index = digit - offset) from an optionally provided conversion string which defaults to
- 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
if 0 ≤ digit - offset < length of string, otherwise digit is returned as integer surrounded by : (colon).
Contents
Usage
- {{digit as char|digit as integer (default 0)|integer offset (default 0)|optional conversion string}}
Valid input
- First argument: digit (default 0) as integer, where digit ≥ offset
- Negative integer digits are used with balanced numeral systems (e.g. for balanced ternary numeral system).
- Second argument: offset as integer (default 0)
- Third argument: String of characters (conversion string) with default value
- 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
Examples
Examples with valid input
Code Result Comment {{digit as char}} 0 (0 as default value and offset) {{digit as char|0|0|}} :0: (empty conversion string) {{digit as char|7}} 7 (0 as default offset) {{digit as char|10}} A {{digit as char|10|0|}} :10: (empty conversion string) {{digit as char|35}} Z {{digit as char|35|0|}} :35: (empty conversion string) {{digit as char|36}} a {{digit as char|61}} z {{digit as char|62}} :62: {{digit as char|89}} :89: {{digit as char|239}} :239: {{digit as char|-1|-1|−0+}} − (see balanced ternary numeral system) {{digit as char|0|-1|−0+}} 0 (see balanced ternary numeral system) {{digit as char|+1|-1|−0+}} + (see balanced ternary numeral system) {{digit as char|-1|-1|∨o∧}} ∨ (see balanced ternary numeral system) {{digit as char|0|-1|∨o∧}} o (see balanced ternary numeral system) {{digit as char|+1|-1|∨o∧}} ∧ (see balanced ternary numeral system) {{digit as char|0|0|αβγδεζηθικλμνξοπρστυφχψω}} α (see base 24) {{digit as char|5|0|αβγδεζηθικλμνξοπρστυφχψω}} ζ (see base 24) {{digit as char|23|0|αβγδεζηθικλμνξοπρστυφχψω}} ω (see base 24) {{digit as char|0|0|abcdefghijklmnopqrstuvwxyz}} a (see base 26) {{digit as char|3|0|abcdefghijklmnopqrstuvwxyz}} d (see base 26) {{digit as char|25|0|abcdefghijklmnopqrstuvwxyz}} z (see base 26)
Examples with invalid input
Code Result Comment {{digit as char|-2|-1|∨o∧}} :-2: {{digit as char|+2|-1|∨o∧}} :2: {{digit as char|2.718}} :2.718: {{digit as char|3.14}} :3.14: {{digit as char|-5}} :-5: {{digit as char|-2.718}} :-2.718: {{digit as char|-3.14}} :-3.14: {{digit as char|-2.718|-3}} :-2.718: {{digit as char|-3.14|-4}} :-3.14: {{digit as char|a}} Expression error: Unrecognized word "a".
Code
{{#ifexpr: ( {{#len:{{{3|0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz}}}}} > 0 ) and <!-- --> ( ( {{{1|0}}} ) = floor ( {{{1|0}}} ) ) and ( ( ( {{{1|0}}} ) - ( {{{2|0}}} ) ) >= 0 ) and <!-- --> ( ( ( {{{1|0}}} ) - ( {{{2|0}}} ) ) < {{#len:{{{3|0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz}}}}} ) | {{#sub:{{{3|0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz}}}|{{#expr: ( {{{1|0}}} ) - ( {{{2|0}}} ) }}|1}} | <nowiki>:</nowiki>{{#expr: {{{1|0}}} }}<nowiki>:</nowiki> }}
See also
- {{digit as char}} base conversion template
- {{digit as int}} base conversion template
- {{from base 10}} base conversion template
- {{to base 10}} base conversion template
- {{from base a to base b}} base conversion template
External links
- Number Bases Conversion from ConvertXY.com
- Jack Sanders-Reed, Base Conversion (Java applet calculator capable of converting a number from/to any base 2-36.)
- Base Conversion (Convert to/from base two through base sixteen.)
- Base Convert (Convert to/from any integer base greater than 1 or Roman numerals.)