| advertise add site services publishers database health videos | ![]() | about toolbar stats live show health store more stuff JOIN/LOGIN |
36 Week Pregnancy, pregnancy at 36 weeks, Baby development at 36 weeks women-health-care.com | Equipment Pieces - Letter 4" Base - Dental... dentalrecord.com |
Base 36 is a positional numeral system using 36 as the radix. 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.[1] Base 36 is therefore the most compact case-insensitive alphanumeric numeral system using ASCII characters, although its radix economy is poor. From a mathematical viewpoint, 36 is a convenient choice for a base in that it is divisible by both 2 and 3, and by their multiples 4, 6, 9, 12 and 18. Each base 36 digit can be represented as two base 6 digits. The most common latinate name for base 36 seems to be hexatridecimal, although sexatrigesimal would arguably be more correct. The intermediate form hexatrigesimal is also sometimes used. For more background on this naming confusion, see the entry for hexadecimal. Another name occasionally seen for base 36 is alphadecimal, a neologism coined based on the fact that the system uses the decimal digits and the letters of the Latin alphabet.
[edit] ExamplesConversion table:
Some numbers in decimal and base 36:
[edit] Conversion32- and 64-bit integers will only hold up to 6 or 12 base-36 digits, respectively. For numbers with more digits, one can use the functions mpz_set_str and mpz_get_str in the GMP arbitrary-precision math library. For floating-point numbers the corresponding functions are called mpf_set_str and mpf_get_str. [edit] Python Conversion Codedef base36encode(number): if not isinstance(number, (int, long)): raise TypeError('number must be an integer') if number < 0: raise ValueError('number must be positive') alphabet = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' base36 = '' while number: number, i = divmod(number, 36) base36 = alphabet[i] + base36 return base36 or alphabet[0] def base36decode(number): return int(number,36) print base36encode(1412823931503067241) print base36decode('AQF8AA0006EH') [edit] C# Conversion Codepublic static string Base36Encode(Int64 value) { char[] base36Chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray(); string returnValue = ""; if (value < 0) { value *= -1; } do { returnValue = base36Chars[value % base36Chars.Length] + returnValue; value /= 36; } while (value != 0); return returnValue; } public static Int64 Base36Decode(string input) { string base36Chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; char[] arrInput = input.ToCharArray(); Array.Reverse(arrInput); Int64 returnValue = 0; for (int i = 0; i < arrInput.Length; i++) { int valueindex = base36Chars.IndexOf(arrInput[i]); returnValue += Convert.ToInt64(valueindex * Math.Pow(36, i)); } return returnValue; } [edit] PHP Code<?php $base_36 = "ZAQFG"; //Sample Base 36 Number $decimal = "7654321"; //Sample Decimal Number echo base_convert($base_36,36,10); //Outputs $base_36 converted to decimal echo base_convert($decimal,10,36); //Outputs $decimal converted to base 36 ?> [edit] Java Codepublic class Base36 { public static int radix = 36; public static String encode(long longValue){ return Long.toString(longValue, radix); } public static long decode(String strValue){ return Long.parseLong(strValue, radix); } public static void main(String[] args) { System.out.println(Base36.encode(1234l)); System.out.println(Base36.decode("ABCD")); } } [edit] JavaScript Codevar dec=2353252; document.write(dec.toString(36)+'<br>');// output: 1efs4 //convert reverse: var base36='1efs4'; document.write(parseInt(base36,36));// output: 2353252 [edit] Ruby Code1234567890.to_s(36) #kf12oi "kf12oi".to_i(36) #1234567890 [edit] Uses in practice
[edit] References
[edit] External links
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ↑ top of page ↑ | about thumbshots |