• c#将十进制转64进制



        //由于用于文件命名,所以将64位中的+转换为=,/转换为_
         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' ,  
            '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' , '=' , '_'  ,  
            };

        public static string to64(long number ,int shift) {
            
                 char[] buf = new char[64];  
            int charPos = 64;  
            int radix = 1 << shift;  
            long mask = radix - 1;  
            do {  
                buf[--charPos] = digits[(int)(number & mask)];  
                number = foo((int)number,shift);  
            } while (number != 0);  
            return new String(buf, charPos, (64 - charPos));  
        }

        public static int foo(int x, int y)
        {
            int mask = 0x7fffffff; //Integer.MAX_VALUE
            for (int i = 0; i < y; i++)
            {
                x >>= 1;
                x &= mask;
            }
            return x;
        }

  • 相关阅读:
    Redis之主从复制原理
    字符编码
    Android studio报错 "No IDEA annotations attached to the JDK 1.8, some issues will not be found" 解决方法
    json
    ajax
    《人月神话》读后感(三)
    Jquery基础
    EL表达式
    Android Studio更改虚拟机位置
    Mybatis之mybatis的介绍
  • 原文地址:https://www.cnblogs.com/Impulse/p/3723713.html
Copyright © 2020-2023  润新知