📜  Java Long.toHexString() 方法

📅  最后修改于: 2022-05-13 01:57:13.351000             🧑  作者: Mango

Java Long.toHexString() 方法


在Java .lang.Long.toHexString()是在Java中内置函数返回long参数的字符串表示为无符号整数在基部16该函数接受单个参数如长数据类型的参数。

句法:

public static String toHexString(long num)

Parameters:  The function accepts a single mandatory parameter 
num -  This parameter specifies the number which is to be converted to Hexadecimal string. 

返回值:该函数将 long 参数的字符串表示形式作为基数为 16 的无符号整数返回。

例子:

Input : 11
Output : b

Input : 12
Output : c

程序1:下面的程序演示了函数的工作。



// Java program to demonstrate working
// of java.lang.Long.toHexString() method
import java.lang.Math;
  
class Gfg1 {
  
    // driver code
    public static void main(String args[])
    {
  
        long l = 11;
  
        // returns the string representation of the unsigned int value
        // represented by the argument in binary (base 2)
        System.out.println("Hex string is " + Long.toHexString(l));
    }
}

输出:

Hex string is b

程序2:下面的程序演示了函数的工作。

// Java program to demonstrate working
// of java.lang.Long.toHexString() method
import java.lang.Math;
  
class Gfg1 {
  
    // driver code
    public static void main(String args[])
    {
  
        long l = 234;
  
        // returns the string representation of the unsigned int value
        // represented by the argument in binary (base 2)
        System.out.println("Hex string is " + Long.toHexString(l));
    }
}

输出:

Hex string is ea