Java - Long Class rotateRight() Method

Long class rotateRight() method: Here, we are going to learn about the rotateRight() method of Long class with its syntax and example. By Preeti Jain Last updated : March 20, 2024

Long 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 long rotateRight (long value, int rotation);

Parameters

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

Return Value

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

Example

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

public class RotateRightOfLongClass {
    public static void main(String[] args) {
        long 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 = Long.rotateRight(value, 3);
            System.out.println("value: " + value);
            ++rotation;
        }
    }
}

Output

value: 6917529027641081856
value: 864691128455135232
value: 108086391056891904

Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.