当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Java Java.lang.Integer.toHexString()用法及代码示例



描述

这个java.lang.Integer.toHexString() 方法将整数参数的字符串表示形式返回为基数为 16 的无符号整数。 以下字符用作十六进制数字:0123456789abcdef

声明

以下是声明java.lang.Integer.toHexString()方法

public static String toHexString(int i)

参数

i─ 这是一个要转换为字符串的整数。

返回值

此方法返回由十六进制(基数为 16)的参数表示的无符号整数值的字符串表示形式。

异常

NA

示例

下面的例子展示了 java.lang.Integer.toHexString() 方法的用法。

package com.tutorialspoint;

import java.lang.*;

public class IntegerDemo {

   public static void main(String[] args) {

      int i = 170;
      System.out.println("Number = " + i);

      /* returns the string representation of the unsigned integer value
         represented by the argument in hexadecimal (base 16) */
      System.out.println("Hex = " + Integer.toHexString(i));
   }  
}

让我们编译并运行上面的程序,这将产生以下结果——

Number = 170
Hex = aa

相关用法


注:本文由纯净天空筛选整理自 Java.lang.Integer.toHexString() Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。