將十進位制整數轉換為十六進位制數字的 Java 程式
使用 toHexString() 方法可將十進位制轉換為十六進位制。該方法以無符號整數的形式返回整數引數的字串表示,底數為 16。以下字元用作十六進位制數字:0123456789abcdef。
以下是語法。
String toHexString(int i)
它僅有一個引數。
- i − 這是一個要轉換為字串的整數。
示例
public class Demo {
public static void main( String args[] ) {
int dec = 45;
System.out.println("Decimal = "+dec);
// converting to hex
System.out.println(Integer.toHexString(dec));
}
}輸出
Decimal = 45 2d
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
JavaScript
PHP