Base36 Encoding and Decoding

From Chorke Wiki
Revision as of 00:47, 30 January 2020 by Shahed (talk | contribs) (→‎References)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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

References