Shift Left in a BigInteger in Java



To shift left in a BigInteger, use the shiftLeft() method.

The java.math.BigInteger.shiftLeft(int n) returns a BigInteger whose value is (this << n). The shift distance, n, may be negative, in which case this method performs a right shift. It computes floor(this * 2n).

Example

 Live Demo

import java.math.*;
public class Demo {
   public static void main(String[] args) {
      BigInteger one;
      one = new BigInteger("25");
      one = one.shiftLeft(3);
      System.out.println("Result: " +one);
   }
}

Output

Result: 200
Updated on: 2020-06-25T10:59:45+05:30

172 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements