Java Integer rotateLeft() method
The rotateLeft() method of Java Integer class returns the value obtained by rotating the 2’s complement binary representation of the given integer value left by the specified number of bits. Syntax public static int rotateLeft (int i , int distance) Parameters The parameter ‘i’ represents the bytes whose value is to be reversed and parameter ‘distance’ represents the number of bit positions to rotate left. Return Value This method returns the value obtained by rotating the 2’s complement binary representation of the integer value left by the specified number of bits. Example 1
public class JavaIntegerRotateLeftExample1 { public static void main(String[] args) { Integer i=120; /* returns the value obtained by rotating the 2’s complement binary representation of the given integer value left by the specified number of bits*/ int left1= Integer.rotateLeft(i,56); System.out.println(left1); //passing negative distance System.out.println(Integer.rotateLeft(12,-12)); } }Output
2013265920 12582912Example 2
public class JavaIntegerRotateLeftExample2 { public static void main(String[] args) { Integer i=120; //returns the same value if distance is passed as zero int left1= Integer.rotateLeft(i,0); System.out.println(left1); } }Output
120Example 3
public class JavaIntegerRotateLeftExample3 { public static void main(String[] args) { Integer i=0; //returns 0 same value if the value of i is 0 int left1= Integer.rotateLeft(i,Integer.MAX_VALUE); System.out.println(left1); } }Output
0