- 10进制转16进制
Integer x = 666; String hex = x.toHexString(x); System.out.println(hex);
- 16进制转10进制
String hex = "fff"; Integer x = Integer.parseInt(hex,16); System.out.println(x);
String hex = "0xfff"; //从第2个字符开始截取 Integer x = Integer.parseInt(hex.substring(2),16); System.out.println(x);
把前面的“0x”去掉
String hex = "0xfff"; Integer x = Integer.parseInt(hex.replaceAll("x", ""),16); System.out.println(x);
通用方法