java.lang.Integer rotateRight(int i, int distance)
Description :
This java tutorial shows how to use the rotateRight() method of Integer class under java.lang package. This method returns Returns the value obtained by rotating the two’s complement binary representation of the specified int value right by the specified number of bits. (Bits shifted out of the right hand, or low-order, side reenter on the left, or high-order.)
Method Syntax :
public static int rotateRight(int i, int distance)
Parameter Input :
DataType | Parameter | Description |
---|---|---|
int | i | the integer value that we want to rotate to the right |
int | distance | this method argument specify the rotation distance |
Method Returns :
The rotateRight(int i, int distance) method simply returns the value obtained by rotating the two’s complement binary representation of the specified int value right by the specified number of bits.
Compatibility Version :
Requires Java 1.5 and up
Exception :
N/A
Java Code Example :
This java example source code demonstrates the use of rotateRoght() method of Integer class. Basically we printed the equivalent binary string of the int argument and then we rotate to the right the two’s complement. Afterwards we convert the rotated value into binary string to see the impact of the rotation.
package com.javatutorialhq.java.examples; import static java.lang.System.*; /* * This example source code demonstrates * the use of rotateRight method of Integer class */ public class IntegerRotateRight { public static void main(String[] args) { int value = 12; // Get the binary equivalent out.println("Binary equivalent:"+Integer.toBinaryString(value)); // get the number of one's int rotatedRight = Integer.rotateRight(value, 3); out.println("New Value:"+rotatedRight); out.println("Rotated Right in Binary:"+Integer.toBinaryString(rotatedRight)); } }
Sample Output :
Running the rotateRight() method example source code of Integer class will give you the following output
Binary equivalent:1100 New Value:-2147483647 Rotated Right in Binary:10000000000000000000000000000001
Exception Scenario :
N/A
Similar Method :
- N/A