Java Integer rotateRight() method
The rotateRight() method of Java Integer class returns the value obtained by rotating the 2’s complement binary representation of the given integer value right by the specified number of bits. Syntax public static int rotateRight (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 right. Return Value This method returns the value obtained by rotating the 2’s complement binary representation of the integer value right by the specified number of bits. Example 1
public class JavaIntegerRotateRightExample1 { 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 right by the specified number of bits*/ int left1= Integer.rotateRight(i,1000); System.out.println(left1); //passing negative distance System.out.println(Integer.rotateRight(12,-12)); } }Output
2013265920 49152Example 2
public class JavaIntegerRotateRightExample2 { public static void main(String[] args) { Integer i=120; //returns the same value if distance is passed as zero int left1= Integer.rotateRight(i,0); System.out.println(left1); } }Output
120Example 3
public class JavaIntegerRotateRightExample3 { public static void main(String[] args) { Integer i=0; //returns 0 same value if the value of i is 0 int left1= Integer.rotateRight(i,Integer.MAX_VALUE); System.out.println(left1); } }Output
0