Java BigInteger shiftRight() method

The shiftRight() method of Java BigInteger class is used to shift the bits to the right side 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 left shift.

Example 1

Test it Now

Output:

Shift Right operation on 5, 2 times gives 1

Example 2

Test it Now

Output:

Shift Right operation on 5, -2 times gives 20

Example 3

Test it Now

Output:

Shift Right operation on 1, 4 times gives 0

Next TopicJava BigInteger




Latest Courses