标签:blog os java ar 2014 sp log amp c
其中有一个私有方法,toUnsignedString(int i, int shift) 是为
public static String toHexString(int i) {
return toUnsignedString(i, 4);
}
public static String toBinaryString(int i) {
return toUnsignedString(i, 1);
}
着两个方法服务的。
final 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' }; private static String toUnsignedString(int i, int shift) { char[] buf = new char[32]; int charPos = 32; int radix = 1 << shift; int mask = radix - 1; do { buf[--charPos] = digits[i & mask]; i >>>= shift; } while (i != 0); return new String(buf, charPos, (32 - charPos)); }以559转为16进制为例:
标签:blog os java ar 2014 sp log amp c
原文地址:http://blog.csdn.net/wufengui1315/article/details/39025091