BigInteger toString() Method in Java Last Updated : 04 Dec, 2018 Summarize Comments Improve Suggest changes Share Like Article Like Report BigInteger Class offers 2 methods for toString(). toString(int radix): The java.math.BigInteger.toString(int radix) method returns the decimal String representation of this BigInteger in given radix. Radix parameter decides on which number base (Binary, octal, hex etc) it should return the string. In case of toString() the radix is by Default 10. If the radix is outside the range of Character.MIN_RADIX to Character.MAX_RADIX inclusive, it will default to 10. Syntax: public String toString(int radix) Parameter: This method accepts a single mandatory parameter radix which is the radix of String representation. Return Value: This method returns decimal String representation of this BigInteger in the given radix. Examples: Input: BigInteger1=321456 radix =2 Output: 1001110011110110000 Explanation: BigInteger1.toString(2)=1001110011110110000. when radix is 2 then function will first convert the BigInteger to binary form then it will return String representation of that binary number. Input: BigInteger1=321456 radix=16 Output: 4e7b0 Explanation: BigInteger1.toString()=4e7b0. when radix is 16 then function will first convert the BigInteger to hexadecimal form then it will return String representation of that hexadecimal number. Below programs illustrate toString(int radix) method of BigInteger class: Example 1: When radix = 2. It means binary form String. Java // Java program to demonstrate // toString(radix) method of BigInteger import java.math.BigInteger; public class GFG { public static void main(String[] args) { // Creating BigInteger object BigInteger b1; b1 = new BigInteger("321456"); // create radix int radix = 2; // apply toString(radix) method String b1String = b1.toString(radix); // print String System.out.println("Binary String of BigInteger " + b1 + " is equal to " + b1String); } } Output: Binary String of BigInteger 321456 is equal to 1001110011110110000 Example 2: When radix = 8 It means octal form String Java // Java program to demonstrate // toString(radix) method of BigInteger import java.math.BigInteger; public class GFG { public static void main(String[] args) { // Creating BigInteger object BigInteger b1; b1 = new BigInteger("34567876543"); // create radix int radix = 8; // apply toString(radix) method String b1String = b1.toString(radix); // print String System.out.println("Octal String of BigInteger " + b1 + " is equal to " + b1String); } } Output: Octal String of BigInteger 34567876543 is equal to 401431767677 Example 3: When radix = 16 It means HexaDecimal form String Java // Java program to demonstrate toString(radix) method of BigInteger import java.math.BigInteger; public class GFG { public static void main(String[] args) { // Creating BigInteger object BigInteger b1; b1 = new BigInteger("8765432123456"); // create radix int radix = 16; // apply toString(radix) method String b1String = b1.toString(radix); // print String System.out.println("Hexadecimal String of BigInteger " + b1 + " is equal to " + b1String); } } Output: Hexadecimal String of BigInteger 8765432123456 is equal to 7f8dc77d040 toString(): The java.math.BigInteger.toString() method returns the decimal String representation of this BigInteger. This method is useful to convert BigInteger to String. One can apply all string operation on BigInteger after applying toString() on BigInteger. Syntax: public String toString() Return Value: This method returns decimal String representation of this BigInteger. Examples: Input: BigInteger1=321456 Output: 321456 Explanation: BigInteger1.toString()=321456. The answer is the String representation of BigInteger Input: BigInteger1=59185482345 Output: 59185482345 Explanation: BigInteger1.toString()=59185482345. The answer is the String representation of BigInteger Below programs illustrate toString() method of BigInteger class: Example: Java // Java program to demonstrate toString() method of BigInteger import java.math.BigInteger; public class GFG { public static void main(String[] args) { // Creating 2 BigInteger objects BigInteger b1, b2; b1 = new BigInteger("35152194853456789"); // apply toString() method String b1String = b1.toString(); // print String System.out.println(b1String); b2 = new BigInteger("7654323234565432345676543234567"); // apply toString() method String b2String = b2.toString(); // print String System.out.println(b2String); } } Output: 35152194853456789 7654323234565432345676543234567 Reference: https://docs.oracle.com/javase/7/docs/api/java/math/BigInteger.html#toString(java.math.BigInteger) Comment More infoAdvertise with us Next Article Boolean toString() Method in Java A AmanSingh2210 Follow Improve Article Tags : Java Java-Functions java-math Java-BigInteger Java-math-package +1 More Practice Tags : JavaJava-BigInteger Similar Reads Integer toOctalString() Method in Java Octal is the base-8 number system and uses the digits 0 to 7 in operation. Octal is widely used in computing on systems like the PDP-8, and IBM mainframes employed 12-bit, 24-bit or 36-bit words. The Java.lang.Integer.toOctalString() method is a built-in function in Java that is used to return a str 3 min read BigInteger valueOf() Method in Java The java.math.BigInteger.valueOf(long value) method returns a BigInteger whose value is equal to value of long passed as parameter. This method is static method so It is not necessary to create object of BigInteger class to use this method.we can call this function by BigInteger.valueOf(long value) 2 min read Boolean toString() Method in Java In Java, the toString() method of the Boolean class is a built-in method to return the Boolean value in string format. The Boolean class is a part of java.lang package. This method is useful when we want the output in the string format in places like text fields, console output, or simple text forma 2 min read Hashtable toString() Method in Java The toString() method in the Hashtable class in Java returns a string representation of the key-value mappings contained in the hashtable. The string is in the form of a comma-separated list of key-value pairs enclosed in curly braces. The toString() method is inherited from the java.util.Hashtable 2 min read Integer toString() in Java The java.lang.Integer.toString() is an inbuilt method in Java which is used to return the String object representing this Integer's value. Syntax : public static String toString() Parameters: The method does not accept any parameters. Return Value:The method returns the string object of the particul 5 min read AtomicInteger toString() method in Java with examples The java.util.concurrent.atomic.AtomicInteger.toString() is an inbuilt method in java that returns the string representation of the current value which is been stored in the integer. Syntax: public String toString() Parameters: The function does not accepts any parameter. Return value: The function 1 min read Like