java中带符号十六进制转换成十进制详解
public void test1(){ String strHex="ffff"; int ia = Integer.parseInt(strHex,16); //不带符号十六进制转换十进制 System.out.println("ia: "+ia); //带符号十六进制转换十进制 String is= String.valueOf((Integer.valueOf(strHex, 16).shortValue())); System.out.println("is: "+is); } } 日志输出: ia: 65535 is: -1
关于单字、双字、单字节16进制转10进制的简单方法(包含负数)
String hexshort = "ff9b";
BigInteger bigint=new BigInteger(hexshort, 16);
short short1 = bigint.shortValue();//单字
String hexint = "ffffff9b";
BigInteger bigint=new BigInteger(hexint, 16);
int int1 = bigint.intValue();//双字
String hexbyte = "9b";
BigInteger bigint=new BigInteger(hexbyte, 16);
byte byte1 = bigint.byteValue();//单字节