在 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
廣告