The toUnsignedString() method of Java Integer class returns a string representation of the argument as an unsigned decimal value.
The second syntax returns a string representation of the given argument as an unsigned integer value in the specified second argument.
Syntax
- public static String toUnsignedString (int i)
- public static String toUnsignedString (int i, int radix)
Parameters
The parameter ‘i’ represents an integer to be converted to an unsigned string and the parameter ‘radix’ represents the radix to use in the string representation.
Return Value
The first syntax of toUnsignedString() method returns an unsigned string representation of the argument.
The second syntax returns an unsigned string representation of the argument in the specified radix.
Example 1
1 2 3 4 5 6 7 8 9 10 11 |
public class JavaIntegerToUnsignedStringExample1 { public static void main(String[] args) { //passing negative value Integer val=-5667; String val1=Integer.toUnsignedString(val); //It returns an unsigned string representation of the argument. System.out.println("Unsigned String Value : "+val1); } } |
Output
1 2 3 |
String Value : 4294961629 |
Example 2
1 2 3 4 5 6 7 8 9 10 11 12 13 |
public class JavaIntegerToUnsignedStringExample2 { public static void main(String[] args) { //passing the max value Integer val=Integer.MAX_VALUE; //passing the max radix int radix=Character.MAX_RADIX; String val1=Integer.toUnsignedString(val,radix); //It returns an unsigned string representation of the argument in the specified radix. System.out.println("String Value : "+val1); } } |
Output
1 2 3 |
String Value : zik0zj |
Example 3
1 2 3 4 5 6 7 8 9 10 11 12 13 |
public class JavaIntegerToUnsignedStringExample2 { public static void main(String[] args) { //passing the min value Integer val=Integer.MIN_VALUE; //passing the min radix int radix=Character.MIN_RADIX; String val1=Integer.toUnsignedString(val,radix); //It returns an unsigned string representation of the argument in the specified radix. System.out.println("String Value : "+val1); } } |
Output
1 2 3 |
String Value : 10000000000000000000000000000000 |