This site is supported by donations to The OEIS Foundation.

Template:From base 10/doc

From OeisWiki
Jump to: navigation, search

This documentation subpage contains instructions, categories, or other information for Template:From base 10. [<Edit> Template:From base 10]

[⧼Purge⧽ Template:From base 10/doc]

The {{from base 10}} base conversion template converts a base 10 real number into its positive integer base (radix) representation , result for which each digit is represented either:

if 0 ≤ digit - offset < length of string

  • as 0-indexed character (with index = digit - offset) from an optionally provided conversion string which defaults to
0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz

else

  • as integer surrounded by : (colon).

Currently supports up to 32 digits for integer part and up to 32 digits for fractional part.

Note: a special proviso has been made for the unary numeral system (base 1, sorf of...) for displaying as many tally marks (up to 100). No tally marks (empty string) for 0. And the luxury of a preceding - sign for negative numbers!

Usage

{{from base 10|a real number x10 in base 10|a positive integer radix (base) b ≥ 2|an optional integer offset|an optional conversion string}}

Valid input

  • First argument: a real number (in base 10),
  • Second argument: a positive integer base (radix) ,
  • Third argument: an optional offset as integer,
  • Fourth argument: an optional conversion string.

Accuracy

Note that the best accuracy offered by Mediawiki is about 14 decimal digits, while 60 -7 = 2799360000000 -1 and 60 -8 = 167961600000000 -1.

Pi (base 60)

Pi in sexagesimal obtained via this template begets

{{from base 10|{{#expr: pi}}|60}} = 3.8Ti0lPr8aKe-520Km-32im-360000000000000
{{from base 10|{{#expr: pi}}|60|0|}} = 3.8294404725538362040-5202048-324448-360000000000000

gets the first 8 sexagesimal digits of A060707 correctly

A060707 Base-60 (Babylonian or sexagesimal) expansion of pi.

{3, 8, 29, 44, 0, 47, 25, 53, 7, 24, 57, 36, 17, 43, 4, 29, 7, 10, 3, 41, 17, 52, 36, 12, 14, 36, 44, 51, 50, 15, 33, 7, 23, 59, 9, 13, 48, 22, 12, 21, 45, 22, 56, 47, 39, 44, ...}

Sqrt(2) (base 60)

Sqrt(2) in sexagesimal obtained via this template begets

{{from base 10|{{#expr: 2^(1/2)}}|60}} = 1.OpA7k64jeK-20-24-56eO0W-56-520000000000000
{{from base 10|{{#expr: 2^(1/2)}}|60|0|}} = 1.24511074664454020-20-24-564024032-56-520000000000000

gets the first 8 sexagesimal digits of A070197 correctly

A070197 Base-60 (or sexagesimal or Babylonian) expansion of sqrt(2). (Pythagoras' constant)

{1, 24, 51, 10, 7, 46, 6, 4, 44, 50, 28, 51, 20, 34, 26, 20, 4, 31, 2, 38, 30, 53, 27, 38, 34, 5, 46, 18, 24, 29, 40, 16, 7, 16, 8, 56, 52, 55, 33, 23, 4, 47, 56, 56, 45, 38, ...}

Examples

Examples with valid input

Code Result Comment
{{from base 10}} 0 (0 as default value)
{{from base 10|0|10|0|}} :0: (empty conversion string)
{{from base 10|374}} 374 (10 as default base)
{{from base 10|-374}} - 374 (10 as default base)
{{from base 10|- 374}} - 374 (10 as default base)
{{from base 10|374|10}} 374
{{from base 10|374|10|0|}} 374 (empty conversion string)
{{from base 10|5|2}} 101
{{from base 10|19|3}} 201
{{from base 10|59|2}} 111011
{{from base 10|-59|2}} - 111011
{{from base 10|59|24|0|αβγδεζηθικλμνξοπρστυφχψω}} γμ
{{from base 10|-59|24|0|αβγδεζηθικλμνξοπρστυφχψω}} - γμ
{{from base 10|4294967295|2}} 11111111111111111111111111111111 2 32 - 1 = 4294967295
{{from base 10|65535|2}} 1111111111111111 2 16 - 1 = 65535
{{from base 10|0.99999999976717|2}} 0.11111111111111111111111111111111 (2 32 - 1) / 2 32 = 0.99999999976717
{{from base 10|0.99998474121094|2}} 0.11111111111111110000000000000000 (2 16 - 1) / 2 16 = 0.99998474121094
{{from base 10|0.99999996996485|2}} 0.11111111111111111111111101111111 (2 32 - 2 7 - 1) / 2 32 = 0.99999996996485
{{from base 10|0.24949645996094|2}} 0.00111111110111110000000000000000 (2 14 - 2 5 - 1) / 2 16 = 0.24949645996094
{{from base 10|67|6}} 151
{{from base 10|24|6|0|}} 40 (empty conversion string)
{{from base 10|67|6|0|}} 151 (empty conversion string)
{{from base 10|0.31802983539095|6}} 0.152410000000000000204044000-4004-4 0 + 1 / 6 + 5 / 6 2 + 2 / 6 3 + 4 / 6 4 + 1 / 6 5 = 0.31802983539095
{{from base 10|107|36}} 2Z
{{from base 10|17.082561728395|36}} H.2YZZZZZZTSG8-12-16-16400-324000000000000 17 + 2 / 36 + 35 / 36 2 = 17.082561728395
{{from base 10|3779|60}} 12x
{{from base 10|49.01749537037|60}} n.12wxxxww8-12C44-56-4-4Ga00000000000000 49 + 1 / 60 + 2 / 60 2 + 59 / 60 3 = 49.01749537037
{{from base 10|-49.01749537037|60}} - n.12wxxxww8-12C44-56-4-4Ga00000000000000
{{from base 10|-49.01749537037|240}} - n.4l175239239170144224-2081281920800000000000000000000 49 + 4 / 240 + 47 / 240 2 + 175 / 240 3 + 239 / 240 4 + 239 / 240 5 + 170 / 240 6 = 49.01749537037
{{from base 10|-49.01749537037|240|0|}} - 49.447175239239170144224-2081281920800000000000000000000 49 + 4 / 240 + 47 / 240 2 + 175 / 240 3 + 239 / 240 4 + 239 / 240 5 + 170 / 240 6 = 49.01749537037


Code Result Comment
{{from base 10|{{to base 10|3:-7:4}}}} 234 (10 as default base, normalized result)
{{from base 10|{{to base 10|-- 3:-7:4}}}} - 234 (10 as default base, normalized result)
{{from base 10|{{to base 10|+1:-1:0:+1|3}}|3}} 201 (balanced ternary to ternary)
{{from base 10|{{to base 10|-1:+1:0:-1|3}}|3}} - 201 (balanced ternary to ternary)


Unary numeral system
Code Result Comment
{{from base 10|-5|1}} - │││││ (- and 5 tally marks)
{{from base 10|0|1}} (no tally marks)
{{from base 10|5|1}} │││││ (5 tally marks)
{{from base 10|27|1}} │││││││││││││││││││││││││││ (27 tally marks)
{{from base 10|59|1}} │││││││││││││││││││││││││││││││││││││││││││││││││││││││││││ (59 tally marks)
{{from base 10|100|1}} ││││││││││││││││││││││││││││││││││││││││││││││││││││││││││││││││││││││││││││││││││││││││││││││││││││ (100 tally marks)
{{from base 10|101|1}} From base 10: Maximum 100 tally marks with unary numeral system (> 100 tally marks)

Examples with invalid input

Code Result Comment
{{from base 10|49|pi}} 1101 (noninteger bases not handled yet!)
{{from base 10|49|e}} 0001 (noninteger bases not handled yet!)
{{from base 10|49|{{phi}}}} 000000000 (noninteger bases not handled yet!) (see Base-φ)
{{from base 10|49|0.5}} Invalid base!
{{from base 10|7|0}} Invalid base!
{{from base 10|-3|-1}} Invalid base!
{{from base 10|7|-6}} Invalid base! (negative bases not handled yet!)

Code




See also



External links