10进制与16进制转换

十进制转十六进制

int a = 194;
int b = 202;
String hex1 = Integer.toHexString(a);
String hex2 = Integer.toHexString(b);
System.out.println(hex1 + " ::: " + hex2);

输出结果为:c2 ::: ca


十六进制转十进制

String hex1 = "c2";
String hex2 = "ca";
int a = Integer.parseInt(hex1, 16);
int b = Integer.parseInt(hex2, 16);
System.out.println(a + " ::: " + b);

输出结果为: 194 ::: 202

你可能感兴趣的:(10进制与16进制转换)