Java.lang Package Classes

Java Integer - rotateRight() Method



The java.lang.Integer.rotateRight() method returns the value obtained by rotating the two's complement binary representation of the specified int value right by the specified number of bits. (Bits shifted out of the right hand, or low-order, side reenter on the left, or high-order.)

Syntax

public static int rotateRight(int i,
                              int distance)

Parameters

i Specify the value whose bits are to be rotated right.
distance Specify the number of bit positions to rotate right.

Return Value

Returns the value obtained by rotating the two's complement binary representation of the specified int value right by the specified number of bits.

Exception

NA.

Example:

In the example below, the java.lang.Integer.rotateRight() method returns the value which is obtained by rotating the two's complement binary representation of the given int value right by the given number of bits.

import java.lang.*;

public class MyClass {
  public static void main(String[] args) {
    
    //creating int values
    int x = 51;
    int y = 251;

    //printing the values obtained by rotating right
    System.out.println("The result is = " + Integer.rotateRight(x, 2)); 
    System.out.println("The result is = " + Integer.rotateRight(y, 3));  
  }
}

The output of the above code will be:

The result is = -1073741812
The result is = 1610612767

❮ Java.lang - Integer