Java Math BigInteger.shiftLeft() 方法


Java Math BigInteger.shiftLeft() 方法

package com.codingdict;



import java.math.*;



public class BigIntegerDemo {



   public static void main(String[] args) {



      // create 3 BigInteger objects

      BigInteger bi1, bi2, bi3;



      bi1 = new BigInteger("10");



      // perform leftshift operation on bi1 using 2 and -2

      bi2 = bi1.shiftLeft(2);

      bi3 = bi1.shiftLeft(-2);



      String str1 = "Leftshift on " + bi1 + ", 2 times gives " +bi2;

      String str2 = "Leftshift on " + bi1 + ",-2 times gives " +bi3;



      // print bi2, bi3 values

      System.out.println( str1 );

      System.out.println( str2 );

   }

}