Home » Java programming language

Java Integer class rotateRight() method with example

Integer class rotateRight() method: Here, we are going to learn about the rotateRight() method of Integer class with its syntax and example.
Submitted by Preeti Jain, on September 28, 2019

Integer class rotateRight() method

  • rotateRight() method is available in java.lang package.
  • rotateRight() method is used to returns the value generated by rotating the binary 2's complement denotation of the given argument (value) right by the given number of bits.
  • rotateRight() method is a static method, it is accessible with the class name too and if we try to access the method with the class object then also we will not get an error.
  • rotateRight() method does not throw an exception at the time of rotating or shifting of bits.

Syntax:

    public static int rotateRight (int value, int rotation);

Parameter(s):

  • int value – represents the integer value to be parsed.
  • int rotation – represents the distance of rotation.

Return value:

The return type of this method is int, it returns an integer value generated by rotating the 2’s complement binary of the given integer value right by the given number of bits.

Example:

// Java program to demonstrate the example 
// of rotateRight (int value, int rotation) method of Integer class

public class RotateRightOfIntegerClass {
    public static void main(String[] args) {
        int value = 3;
        int rotation = 1;

        // Iterates till the value of rotation reaches
        while (rotation < 4) {
            // It return the value generated by rotating the 2's complement 
            // of the given argument (value) right by the given number of bits
            value = Integer.rotateRight(value, 3);
            System.out.println("value: " + value);
            ++rotation;
        }
    }
}

Output

value: 1610612736
value: 201326592
value: 25165824






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.