Java.lang Package Classes

Java Long - toUnsignedString() Method



The java.lang.Long.toUnsignedString() method returns a string representation of the first argument as an unsigned integer value in the radix specified by the second argument. If the radix is smaller than Character.MIN_RADIX or larger than Character.MAX_RADIX, then the radix 10 is used instead.

Syntax

public static String toUnsignedString(long i,
                                      int radix)

Parameters

i Specify an integer to be converted to an unsigned string.
radix Specify the radix to use in the string representation.

Return Value

Returns an unsigned string representation of the argument in the specified radix.

Exception

NA.

Example:

In the example below, the java.lang.Long.toUnsignedString() method is used to convert the given long value to a string by an unsigned conversion in the specified radix.

import java.lang.*;

public class MyClass {
  public static void main(String[] args) {
    
    //creating long value
    long x = 25;
    long y = 111;

    //printing UnsignedString value of x in binary system
    System.out.print("UnsignedString value of x using radix=2 is: ");
    System.out.println(Long.toUnsignedString(x, 2)); 

    //printing UnsignedString value of y in hexadecimal system
    System.out.print("UnsignedString value of y using radix=16 is: ");
    System.out.println(Long.toUnsignedString(y, 16));  
  }
}

The output of the above code will be:

UnsignedString value of x using radix=2 is: 11001
UnsignedString value of y using radix=16 is: 6f

❮ Java.lang - Long

5