Integer.rotateLeft() method in Java


The Integer.rotateLeft() method returns the value obtained by rotating the two's complement binary representation of the specified int value i left by the specified number of bits. The following is the syntax.

int rotateLeft(int i, int distance)

Here are the parameters.

  • i − This is the int value.
  • distance − This is the rotation distance.

Example

 Live Demo

public class Demo {
   public static void main(String []args) {
      int val = 1;
      for (int i = 0; i < 4; i++) {
         val = Integer.rotateLeft(val, 1);
         System.out.println(val);
      }
   }
}

Output

2
4
8
16

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 26-Jun-2020

77 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements