Java.lang Package Classes

Java Integer - toUnsignedString() Method



The java.lang.Integer.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(int i,
                                      int radix)

Parameters

i Specify an integer to be converted to an unsigned string.
i 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.Integer.toUnsignedString() method returns a string representation of the argument as an unsigned integer value using specified radix.

import java.lang.*;

public class MyClass {
  public static void main(String[] args) {

    //creating int values
    int x = 31;
    int y = 51;
    int z = 111;

    //creating toUnsignedString value of int values
    //using binary, octal and hexadecimal radix
    String p = Integer.toUnsignedString(x, 2);
    String q = Integer.toUnsignedString(y, 8);
    String r = Integer.toUnsignedString(z, 16);

    //printing toUnsignedString value of int values
    System.out.println("toUnsignedString value of x is: " + p); 
    System.out.println("toUnsignedString value of y is: " + q);
    System.out.println("toUnsignedString value of z is: " + r);  
  }
}

The output of the above code will be:

toUnsignedString value of x is: 11111
toUnsignedString value of y is: 63
toUnsignedString value of z is: 6f

❮ Java.lang - Integer

5