This article needs additional citations for verification. (November 2008) (Learn how and when to remove this template message)
Base36 is a binary-to-text encoding scheme that represents binary data in an ASCII string format by translating it into a radix-36 representation. The choice of 36 is convenient in that the digits can be represented using the Arabic numerals 0–9 and the Latin letters A–Z (the ISO basic Latin alphabet).
Each base36 digit needs less than 6 bits of information to be represented.
Signed 32- and 64-bit integers will only hold at most 6 or 13 base-36 digits, respectively (that many base-36 digits overflow the 32- and 64-bit integers). For example, the 64-bit signed integer maximum value of "9223372036854775807" is "1Y2P0IJ32E8E7" in base-36.
PHP, like Java, supports conversion from/to String to different bases from 2 up to 36. Use the base_convert function, available since PHP 4.
Python Code to encode BASE36 from BASE10
0 def base36encode(integer): 1 chars, encoded, sign = '0123456789abcdefghijklmnopqrstuvwxyz', '', '' 2 3 if integer < 0: 4 sign = '-' 5 integer = -1*integer 6 7 elif integer == 0: 8 sign = '0' 9 10 while integer > 0: 11 integer, remainder = divmod(integer, 36) 12 encoded = chars[remainder] + encoded 13 14 return sign+encoded
Visual Basic .NET implementation
Public Function ToBase36String(i as UInteger) As String Const rainbow = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" Dim sb = New StringBuilder() Do sb.Insert(0, rainbow(i Mod 36)) i /= 36 Loop While i <> 0 Return sb.ToString() End Function
- A discussion about the proper name for base 36 at the Wordwizard Clubhouse
- The Prime Lexicon, a list of words that are prime numbers in base 36
- A Binary-Octal-Decimal-Hexadecimal-Base36 converter written in PHP
- A C# base 36 encoder and decoder
- Code sample in C# that demonstrates the HexaTriDecimal Numbering System including string parsing, as well as increment/decrement operations