Java 語言 `Integer.toHexString()` 方法及其示例


`java.lang.Integer.toHexString()` 方法以 16 進制中的無符號整數的對數形式返回整型引數的字串表示。

我們現在看一個示例 −

示例

import java.lang.*;
public class Main {
   public static void main(String[] args) {
      int i = 160;
      System.out.println("Number = " + i);
      System.out.println("Hex = " + Integer.toHexString(i));
   }
}

輸出

Number = 160
Hex = a0

示例

現在我們看一個負數的另一個示例 −

import java.lang.*;
public class Main {
   public static void main(String[] args) {
      int i = -160;
      System.out.println("Number = " + i);
      System.out.println("Hex = " + Integer.toHexString(i));
   }
}

輸出

Number = -160
Hex = ffffff60

更新於: 2019-09-23

122 次瀏覽

開啟你的 事業

完成課程並獲得認證

開始
廣告
© . All rights reserved.