Java Math Biginteger ToString_radix


Java Math Biginteger ToString_radix

package com.codingdict;



import java.math.*;



public class BigIntegerDemo {



   public static void main(String[] args) {



      // create 2 BigInteger objects

      BigInteger bi1, bi2;



      // create 2 String objects

      String s1, s2;



      bi1 = new BigInteger("16");

      bi2 = new BigInteger("-16");



      // assign String value of bi1, bi2 to s1, s2 using radix

      s1 = bi1.toString(8); // octal value of bi1

      s2 = bi2.toString(2); // binary value of bi2



      String str1 = "String value of " +bi1+ " in radix 8 is " +s1;

      String str2 = "String value of " +bi2+ " in radix 2 is " +s2;



      // print s1, s2 values

      System.out.println( str1 );

      System.out.println( str2 );

   }

}