Java - Integer Class rotateLeft() Method

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

Integer class rotateLeft() method

  • rotateLeft() method is available in java.lang package.
  • rotateLeft() method is used to returns the value generated by rotating the binary 2's complement denotation of the given argument (value) left by the given number of bits.
  • rotateLeft() 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.
  • rotateLeft() method does not throw an exception at the time of rotating or shifting of bits.

Syntax

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

Parameters

  • 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 left by the given number of bits.

Example

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

public class RotateLeftOfIntegerClass {
    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) left 
            // by given number of bits
            value = Integer.rotateLeft(value, 3);
            System.out.println("value: " + value);
            ++rotation;
        }
    }
}

Output

value: 24
value: 192
value: 1536

Comments and Discussions!

Load comments ↻





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