首页 文章资讯内容详情

java.lang.Integer.toHexString()方法与示例

2026-06-04 1 花语

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