// 以其他数字为基底的整数转换常式
byte b = Byte.parseByte("1011", 2); // 二进位的 1011 , 在十进位中则是 11
short sh = Short.parseShort("ff", 16); // 十六进位的 ff , 在十进位中为 255 // valueOf() 方法可以处理任意的基底(base)
int i = Integer.valueOf("egg", 17).intValue(); // 以 17 为基底 // decode() 方法可以处理八进位、十进位或十六进位
// 要看该字串前面的数字为何
short sh = Short.decode("0377").byteValue(); // 以 0 开头表示是八进位
int i = Integer.decode("0xff").shortValue(); // 以 0x 开头表示是十六进位
long l = Long.decode("255").intValue(); // 其他的数字则表示是十进位 // 能将数字转换为字串的 Integer 类别
String decimal = Integer.toString(42);
String binary = Integer.toBinaryString(42);
String octal = Integer.toOctalString(42);
String hex = Integer.toHexString(42);
String base36 = Integer.toString(42, 36);
\ddd 是8进制数ddd
\uxxxx是16进制数xxxx(必须输满4位)
哈哈!
class n{
public static void main(String args[]){
long o='\123';
long hex='\uffff';
System.out.println("o="+o+"hex="+hex);
}
}
long i=0xfff4是16进制数!