Parse and format to arbitrary radix <= Character.MAX_RADIX in Java

Java 8Object Oriented ProgrammingProgramming

Let us set a radix here as.

// radix
int r = 32;

Include the radix here as a BigInteger constructor.

BigInteger one = new BigInteger("vv", r);

Now get its string representation −

String strResult = one.toString(radix);

The following is an example −

Example

 Live Demo

import java.math.*;
public class Demo {
   public static void main(String[] args) {
      // radix
      int r = 32;
      BigInteger one = new BigInteger("vv", r);
      String strResult = one.toString(r);
      System.out.println(strResult);
   }
}

Output

vv
raja
Published on 20-Dec-2018 10:39:04
Advertisements