Base36 Encoding and Decoding: Difference between revisions
Jump to navigation
Jump to search
(Created page with "==Java== <source lang="java"> public class Base36 { public static final int RADIX = 36; public static String encode(int integer) { String base36 = Integer.toS...") |
|||
Line 84: | Line 84: | ||
==References== | ==References== | ||
* [https://en.wikipedia.org/wiki/Base64 Base64] | * [https://en.wikipedia.org/wiki/Base64 Base64] | ||
* [https://en.wikipedia.org/wiki/Base36 Base36] | * [https://en.wikipedia.org/wiki/Base36 Base36] | ||
* [https://en.wikipedia.org/wiki/Base32 Base32] | * [https://en.wikipedia.org/wiki/Base32 Base32] |
Latest revision as of 00:47, 30 January 2020
Java
public class Base36 {
public static final int RADIX = 36;
public static String encode(int integer) {
String base36 = Integer.toString(integer, RADIX);
return base36.toUpperCase();
}
public static int decode(String base36) {
String lower = base36.toLowerCase();
return Integer.parseInt(lower, RADIX);
}
}
JavaScript
var Chorke=Chorke||(function(me){
me = {
$class : 'Chorke',
$package : 'Default',
};
return me;
})();
/**
* @public
* @static
*/
;Chorke.Base36||(function($, me, RADIX){
RADIX = 36;
me = {
$package: 'Chorke',
$class : 'Chorke.Base36',
Encode : function(number, base36){
base36 = (number).toString(RADIX)
base36 = base36.toUpperCase()
return base36
},
Decode : function(base36, number){
number = parseInt(base36, RADIX)
return number
}
};
$.Base36 = me;
})(Chorke);
|
/**
* @public
* @static
*/
;Chorke.Severity||(function($, w, me){
me = {
$package: 'Chorke',
$class : 'Chorke.Severity',
Info : function(message){
w.console&&w.console.info(message)
}
};
$.Severity = me;
})(Chorke, window);
/**
* @anonymous
* @static
*/
(function($){
$.Severity.Info($.Base36.Encode(123456789));
$.Severity.Info($.Base36.Decode("2R4Y"));
})(Chorke);
// Output
// 21I3V9
// 128482
|