Java 中十六進位制整數字面量
對於十六進位制,需要將 0x 或 0X 放在數字的開頭。
注意 − 數字 10 到 15 在十六進位制中由 a 到 f(A 到 F)表示
以下是一些宣告並初始化為 int 型別的十六進位制整數字面量的示例。
int one = 0X123; int two = 0xABC;
示例
public class Demo { public static void main(String []args) { int one = 0X123; int two = 0xABC; System.out.println("Hexadecimal: "+one); System.out.println("Hexadecimal: "+two); } }
輸出
Hexadecimal: 291 Hexadecimal: 2748
廣告