Bit shifting is used in programming and has at least one variation in each programming language. Java has a single Logical right shift operator (>>). Bit shifting is a type of bitwise operation. Bit shifting is done on all the bits of a binary value which moves the bits by a definite number of places to the right. If the value 0100; (ie. 4) is shifted right, it becomes 0010; (ie. 2)which is again shifted to the right again it becomes 0001; or 1.
The java.lang.Integer.rotateRight() is the method which returns the value we get by rotating the two’s complement binary representation of the specified int value a towards the right by a specified number of bits. Bits are shifted towards the right hand i.e., the lower-order.
public static int rotateRight(int a, int shifts)
Parameters: The method takes two parameters:
- a : This is of integer type and refers to the value on which operation is to be performed.
- shifts : This is also of integer type and refers to the distance of rotation.
Returns: 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.
Below programs illustrate the Java.lang.Integer.rotateRight() method:
Program 1: For a positive number.
16 4 1
Program 2: For a negative number.
-42 -1073741835 1879048189
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Integer sum() Method in Java
- Java Integer bitCount() method
- Integer valueOf() Method in Java
- Java Integer byteValue() method
- Integer floatValue() Method in Java
- Integer shortValue() Method in Java
- Integer reverseBytes() Method in Java
- Integer rotateLeft() Method in Java
- Integer reverse() Method In Java
- Java Integer compareTo() method
- Integer intValue() Method in Java
- Integer highestOneBit() Method in Java
- Integer signum() Method in Java
- Integer lowestOneBit() Method in Java
- Integer doubleValue() Method in Java
- Java Integer compare() method
- Integer hashCode() Method in Java
- Integer.numberOfLeadingZeros() Method in Java With Example
- Integer.numberOfTrailingZeros() Method in Java with Example
- Integer decode() Method in Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : nidhi_biet