Java.lang Package Classes

Java Integer - rotateLeft() Method



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

Syntax

public static int rotateLeft(int i,
                             int distance)

Parameters

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

Return Value

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

Exception

NA.

Example:

In the example below, the java.lang.Integer.rotateLeft() method returns the value which is obtained by rotating the two's complement binary representation of the given int value left 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 left
    System.out.println("The result is = " + Integer.rotateLeft(x, 2)); 
    System.out.println("The result is = " + Integer.rotateLeft(y, 3));  
  }
}

The output of the above code will be:

The result is = 204
The result is = 2008

❮ Java.lang - Integer