zoukankan      html  css  js  c++  java
  • UUID 压缩为22位

    public class Generator {
    
        private static char[] BASE64 = "abcdefghijklmnopqrstuvwxyz_ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789".toCharArray();
    
        public static String generateUUID() {
            UUID uuid = UUID.randomUUID();
            char[] chs = new char[22];
            long most = uuid.getMostSignificantBits();
            long least = uuid.getLeastSignificantBits();
            int high = (int)((most >> 13) ^ (least >> 31)) & 0x3c;
            int k = chs.length - 1;
            for(int i = 0; i < 10; i++, least >>>= 6) {
                chs[k--] = BASE64[(int)(least & 0x3f)];
            }
            chs[k--] = BASE64[(int)((least & 0x3f) | (most & 0x30))];
            most >>>= 2;
            for(int i = 0; i < 10; i++, most >>>= 6) {
                chs[k--] = BASE64[(int)(most & 0x3f)];
            }
            chs[k--] = BASE64[(int)(high | most)];
            return new String(chs);
        }
    }
  • 相关阅读:
    Bacula Plugins
    getopt、getopt_long命令参数
    Notepad++ 快捷键
    make命令
    Linux目录结构
    rhel安装输入法
    libtool编译
    install和cp
    dlopen动态链接库操作
    结构体赋值
  • 原文地址:https://www.cnblogs.com/dazhaxie/p/4809865.html
Copyright © 2011-2022 走看看