MCPcopy Create free account
hub / github.com/diyhi/bbs / toHex

Method toHex

src/main/java/cms/utils/UUIDUtil.java:73–100  ·  view source on GitHub ↗

将长整型数值转换为指定的进制数(最大支持62进制,字母数字已经用尽) @param i @param radix @return

(long i, int radix)

Source from the content-addressed store, hash-verified

71 * @return
72 */
73 private static String toHex(long i, int radix) {
74 if (radix < MIN_RADIX || radix > MAX_RADIX)
75 radix = 10;
76 if (radix == 10)
77 return Long.toString(i);
78
79 final int size = 65;
80 int charPos = 64;
81
82 char[] buf = new char[size];
83 boolean negative = (i < 0);
84
85 if (!negative) {
86 i = -i;
87 }
88
89 while (i <= -radix) {
90 buf[charPos--] = digits[(int) (-(i % radix))];
91 i = i / radix;
92 }
93 buf[charPos] = digits[(int) (-i)];
94
95 if (negative) {
96 buf[--charPos] = '-';
97 }
98
99 return new String(buf, charPos, (size - charPos));
100 }
101
102 static NumberFormatException forInputString(String s) {
103 return new NumberFormatException("For input string: \"" + s + "\"");

Callers 1

digitsMethod · 0.95

Calls 1

toStringMethod · 0.45

Tested by

no test coverage detected