os :windows7 x64
jdk:jdk-8u131-windows-x64
ide:Eclipse Oxygen Release (4.7.0)
code:
package jizuiku3; public class Demo010 { public static void main(String[] args) { System.out.println(Integer.toString(127, 2));//127的二进制 System.out.println(Integer.toString(36*35, 36));//127的三十六进制 //三十六进制 => 26个字母 + 10个数字,(⊙o⊙)哦 } }
result:
sourceCode:
public static String toString(int i, int radix) { if (radix < Character.MIN_RADIX || radix > Character.MAX_RADIX) radix = 10; /* Use the faster version */ if (radix == 10) { return toString(i); } char buf[] = new char[33]; boolean negative = (i < 0); int charPos = 32; if (!negative) { i = -i; } while (i <= -radix) { buf[charPos--] = digits[-(i % radix)]; i = i / radix; } buf[charPos] = digits[-i]; if (negative) { buf[--charPos] = ‘-‘; } return new String(buf, charPos, (33 - charPos)); }
Java优秀,值得学习。
学习资源:API手册+Java源码+清净的心地。
时间: 2024-11-06 01:33:48