Java Integer.rotateRight(int i, int distance) example

Java Integer.rotateRight(int i, int distance) example

By Yashwant Chavan, Views 4, Date 24-Apr-2018

In this java tutorial, You will learn how to use rotateRight(int i, int distance) method of Integer class. This 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. Bits shifted out of the right hand, or low-order, side reenter on the left, or high-order. Note that right rotation with a negative distance is equivalent to left rotation.

tags Java

Returns the value obtained by rotating the two's complement binary representation of the specified int value right by the specified number of bits.

Syntax

public static int rotateRight(int i, int distance)

Returns

The value obtained by rotating the two's complement binary representation of the specified int value right by the specified number of bits.

Java Integer rotateRight(int i, int distance) example

  • Assign integer value.
  • Integer.rotateRight(firstValue, 12);It will returns the value obtained by rotating right.
  • Print the values.
package com.technicalkeeda;

public class App {

    public static void main(String[] args) {

        Integer firstValue = 2;

        int result = Integer.rotateRight(firstValue, 12);

        System.out.println("Value obtained by rotating right  :- " + result);
    }
}

output

Value obtained by rotating right  :- 2097152
Yashwant

Yashwant

Hi there! I am founder of technicalkeeda.com and programming enthusiast. My skills includes Java,J2EE, Spring Framework, Nodejs, PHP and lot more. If you have any idea that you would want me to develop? Lets connect: yashwantchavan[at][gmail.com]