convert. Converting number from one base to another [3.4.1]

^math:convert[number](base-from;base-to)
^math:convert[number|file](base-from;base-to)[options[3.4.6]
^math:convert[
number|file][alphabet](base-to)[options
[3.4.6]
^math:convert[
number|file](base-from)[alphabet][options
[3.4.6]
^math:convert[
number|file][alphabet][alphabet][options
[3.4.6]

Method converts a number (can be in the form of a binary file) from one base to another.
The base can be specified as an alphabet containing at least two characters, as a number from 2 (equivalent to the alphabet 01) to 16 (equivalent to the alphabet
0123456789ABCDEF), as number 256 (equivalent to the alphabet of all ASCII characters).

Options hash can be specified:
·$.format[string|file] - result format, string by default.  


Numbers can range
- 32 bits, to 0xFFFFFFFF.
- 64 bits, to 0xFFFFFFFFFFFFFFFF.   [3.4.4]
- arbitary precision.      [3.4.6]

Examples

^math:convert[255](10;16) - returns FF string

^math:convert[A](256;10) / ^math:convert[A](256;16) - returns ASCII code of the character 'A' in a decimal and hexadecimal form (65 / 41).

^math:convert[hello](256)[0123456789abcdefghijklmnopqrstuvwxyz] - returns string 'hello' representation in Base36 (5pzcszu7).

^math:convert[5pzcszu7][0123456789abcdefghijklmnopqrstuvwxyz](256) - decodes string 'hello' from its Base36 representation.



Copyright © 1997–2021 Art. Lebedev Studio | http://www.artlebedev.com Last updated: 25.01.2021