In Integer.java, there is the following piece of code:
/**
* All possible chars for representing a number as a String
*/
final static char[] digits = {
'0' , '1' , '2' , '3' , '4' , '5' ,
'6' , '7' , '8' , '9' , 'a' , 'b' ,
'c' , 'd' , 'e' , 'f' , 'g' , 'h' ,
'i' , 'j' , 'k' , 'l' , 'm' , 'n' ,
'o' , 'p' , 'q' , 'r' , 's' , 't' ,
'u' , 'v' , 'w' , 'x' , 'y' , 'z'
};
I thought all the digits/characters you would ever need are in the range 0-9 and letters A to F. Letters (A,B,C,D,E and F) would be used only when the numbers are represented in base 16 (hexadecimal).
Why does the Javadoc say "All possible chars" ? Are the letters from G to Z actually used ? I would think that they could be used if the base, we represent the numbers in, is greater than 16.
The toString
method supports arbitrary bases (like 20) up to MAX_RADIX
which is defined as 36
"Base36: Uses in practice" explains some common use cases.
- The Remote Imaging Protocol for bulletin board systems used base 36 notation for transmitting coordinates in a compact form.
- Many URL redirection systems like TinyURL or SnipURL/Snipr also use base 36 integers as compact alphanumeric identifiers.
- Geohash-36, a coordinate encoding algorithm, uses radix 36 but uses a mixture of lowercase and uppercase alphabet characters in order to avoid vowels, vowel-looking numbers, and other character confusion.
- Various systems such as RickDate use base 36 as a compact representation of Gregorian dates in file names, using one digit each for the day and the month.
- [and many more]
Protocol designers sometimes need a compact, ASCII alphanumeric, case-insensitive scheme for encoding integers. Base36 fits the bill.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With