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


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

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 30-Jul-2019

163 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements