Java BigInteger shiftLeft() Method

The shiftLeft() method of Java BigInteger class is used to shift the bits to the left by n times (shift distance). This method returns a BigInteger whose value is (this<<n). This method Computes floor (this * 2n).

Syntax:

Parameter:

n- shift distance, in bits

Returns:

This method returns (this<< n).

Exception:

NA

Note: The shift distance n, may be negative, in which case this method performs a right shift.

Example 1

Test it Now

Output:

Shift left operation on 5, 2 times gives 20

Example 2

Test it Now

Output:

Shift left operation on 5, -2 times gives 1

Example 3

Test it Now

Output:

Shift left operation on 1, 4 times gives 16

Next TopicJava BigInteger




Latest Courses