This site is supported by donations to The OEIS Foundation.
Template:Digit as int
From OeisWiki
The following documentation is located at Template:Digit as int/doc. [<Edit> Template:Digit as int/doc]
[⧼Purge⧽ Template:Digit as int]
[⧼Purge⧽ Template:Digit as int]
The {{digit as int}} base conversion template converts a single character digit into an integer digit = index + offset, where index is the character index (0-indexed) of character digit within an optionally provided conversion string which defaults to
- 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
if character digit is within the conversion string, otherwise offset is returned as the integer digit.
Contents
Usage
- {{digit as int|single character digit (default 0)|integer offset (default 0)|optional conversion string}}
Valid input
- First argument: single character digit (default 0, i.e. zero)
- Second argument: integer offset (default 0)
- Negative offset is used to get negative integer digits for balanced numeral systems (e.g. balanced ternary).
- Third argument: Conversion string of characters with default value
- 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
Examples
Examples with valid input
Code Result Comment {{digit as int}} 0 (0 as default value and offset) {{digit as int|7}} 7 (0 as default offset) {{digit as int|A}} 10 {{digit as int|Z}} 35 {{digit as int|a}} 36 {{digit as int|z}} 61 {{digit as int|α|0|αβγδεζηθικλμνξοπρστυφχψω}} 0 (see base 24) {{digit as int|ζ|0|αβγδεζηθικλμνξοπρστυφχψω}} 5 (see base 24) {{digit as int|ω|0|αβγδεζηθικλμνξοπρστυφχψω}} 23 (see base 24) {{digit as int|−|-1|−0+}} -1 (see balanced ternary numeral system) {{digit as int|0|-1|−0+}} 0 (see balanced ternary numeral system) {{digit as int|+|-1|−0+}} 1 (see balanced ternary numeral system) {{digit as int|∨|-1|∨o∧}} -1 (see balanced ternary numeral system) {{digit as int|o|-1|∨o∧}} 0 (see balanced ternary numeral system) {{digit as int|∧|-1|∨o∧}} 1 (see balanced ternary numeral system) {{digit as int|a|0|abcdefghijklmnopqrstuvwxyz}} 0 (see base 26) {{digit as int|d|0|abcdefghijklmnopqrstuvwxyz}} 3 (see base 26) {{digit as int|z|0|abcdefghijklmnopqrstuvwxyz}} 25 (see base 26)
Examples with invalid input (offset is returned as integer digit)
Code Result Comment {{digit as int|α}} 0 (offset is returned) {{digit as int|Ω|0|αβγδεζηθικλμνξοπρστυφχψω}} 0 (offset is returned) {{digit as int|∞}} 0 (offset is returned) {{digit as int|2.718}} 0 (offset is returned) {{digit as int|-5}} 0 (offset is returned) {{digit as int|∧|-1|−0+}} -1 (offset is returned)
Code
{{#expr: 0{{#pos:{{{3|0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz}}}|{{{1|0}}}}} + ( {{{2|0}}} ) }}
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.)