This site is supported by donations to The OEIS Foundation.

Template:Digit as int

From OeisWiki
Jump to: navigation, search

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.

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


External links