在 Java 中将十进制整数转换为十六进制数
要将十进制整数转换为十六进制,请使用 Integer.toHexString() 方法。我们假设以下内容是我们的十进制整数。
int decInt = 25;
以下是如何使用 Integer.toHexString() 方法将十进制整数转换为十六进制数。
String myHex = Integer.toHexString(decInt);
以下是完整示例。
示例
public class Demo { public static void main(String []args) { int decInt = 25; System.out.println("Decimal Integer = "+decInt); String myHex = Integer.toHexString(decInt); System.out.println("Hexadecimal = "+myHex); } }
输出
Decimal Integer = 25 Hexadecimal = 19
广告