A Java implementation of a 64-bit binary conversion

Source: Internet
Author: User
public class Conversionalphanumericutil {/** the logger. * * Private static final Logger logger = LOGGERFACTORY.G

    Etlogger (Conversionalphanumericutil.class);
    private static final String basedigits = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    private static final int BASE = Basedigits.length ();
    private static final char[] Digitschar = Basedigits.tochararray ();
    private static final int fast_size = ' Z ';

    private static final int[] Digitsindex = new Int[fast_size + 1];
        static {for (int i = 0; i < fast_size i++) {Digitsindex[i] =-1;
        }//for (int i = 0; i < BASE; i++) {Digitsindex[digitschar[i]] = i;
        The public static long decode (String s) {long result = 0L;
        Long multiplier = 1;
            for (int pos = S.length ()-1; Pos >= 0; pos--) {int index = GetIndex (s, POS);
            result = = Index * multiplier; MulTiplier *= BASE;
    return result;  public static String encode (long) {if (number < 0) Logger.error ("number (BASE62) must
        Be positive: "+ number);
        if (number = = 0) return "0";
        StringBuilder buf = new StringBuilder ();
            while (number!= 0) {buf.append (digitschar[(int) (number% BASE)]);
        Number/= BASE;
    Return Buf.reverse (). toString ();
        private static int GetIndex (String s, int pos) {char c = S.charat (POS);
        if (C > Fast_size) {logger.error ("Unknow character for Base62:" + s);
        int index = digitsindex[c];
        if (index = = 1) {logger.error ("Unknow character for Base62:" + s);
    } return index;
 }
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.