Java 中将整数转换成十六进制字符串
Java 中的 Integer.toHexString() 方法可将整数转换为十六进制字符串。
我们有以下整数。
int val1 = 5; int val2 = 7; int val3 = 13;
将上述整数转换为十六进制字符串。
Integer.toHexString(val1); Integer.toHexString(val2); Integer.toHexString(val3);
示例
public class Demo { public static void main(String[] args) { int val1 = 5; int val2 = 7; int val3 = 13; int val4 = 23; int val5 = 30; System.out.println("Converting integer "+val1+" to Hex String: "+Integer.toHexString(val1)); System.out.println("Converting integer "+val2+" to Hex String: "+Integer.toHexString(val2)); System.out.println("Converting integer "+val3+" to Hex String: "+Integer.toHexString(val3)); System.out.println("Converting integer "+val4+" to Hex String: "+Integer.toHexString(val4)); System.out.println("Converting integer "+val5+" to Hex String: "+Integer.toHexString(val5)); } }
输出
Converting integer 5 to Hex String: 5 Converting integer 7 to Hex String: 7 Converting integer 13 to Hex String: d Converting integer 23 to Hex String: 17 Converting integer 30 to Hex String: 1e
广告