Java Long.toHexString() Method
Last Updated :
05 Dec, 2018
Improve
The Java.lang.Long.toHexString() is a built-in function in Java which returns a string representation of the long argument as an unsigned integer in base 16. The function accepts a single parameter as an argument in Long data-type.
Syntax:
Java
Output:
Java
Output:
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.Return Value: The function returns a string representation of the long argument as an unsigned integer in base 16. Examples:
Input : 11 Output : b Input : 12 Output : cProgram 1: The program below demonstrates the working of function.
// 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));
}
}
// 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 bProgram 2: The program below demonstrates the working of function.
// 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));
}
}
// 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