Integer rotateLeft() Method in Java Last Updated : 18 Oct, 2019 Comments Improve Suggest changes Like Article Like Report Bit shifting is a type of bitwise operation which is performed on all the bits of a binary value by moving the bits by a definite number of places towards left or right. Java has a single Logical left shift operator (<< ). When the value 0001(i.e., 1) is shifted left, it becomes 0010(i.e., 2) which on shifting again to the left becomes 0100 or 4. The same process is applied for the right shift operation. The java.lang.Integer.rotateLeft() method is used to shift the bits of an Integer value, represented in its binary 2's complementary form towards left by a specified number of bits. (Bits are shifted to the left or higher-order). Syntax: public static int rotateLeft(int value, int shifts) Parameters: The method takes two parameters: a : This is of integer type and refers to the value on which operation is to be performed. shifts : This is also of integer type and refers to the distance of rotation. Return Value: The method returns the value obtained by rotating the two's complement binary representation of the specified int value towards left by the specified number of shift bits. Examples: Input: 12 Output: 24 Explanation: Consider an integer a = 12 Binary Representation = 00001100 After 1 left shift it will become=00011000 So that is= 24 Below programs illustrate the java.lang.Integer.rotateLeft() method. Program 1: For a positive number. java // Java program to illustrate the // Java.lang.Integer.rotateLeft() method import java.lang.*; public class Geeks { public static void main(String[] args) { int a = 2; int shifts = 0; while (shifts < 6) // It will return the value obtained by rotating left { a = Integer.rotateLeft(a, 2); System.out.println(a); shifts++; } } } Output: 8 32 128 512 2048 8192 Program 2: For a negative number. java // Java program to illustrate the // Java.lang.Integer.rotateLeft() method import java.lang.*; public class Geeks { public static void main(String[] args) { int a = -16; int shifts = 0; while (shifts < 2) // It will return the value obtained by rotating left { a = Integer.rotateLeft(a, shifts); System.out.println(a); shifts++; } } } Output: -16 -31 Program 3: For a decimal value and string. Note: It returns an error message when a decimal value and string is passed as an argument java // Java program to illustrate the // Java.lang.Integer.rotateLeft() method import java.lang.*; public class Geeks { public static void main(String[] args) { int a = 15.71; int shifts = 0; while (shifts < 2) { a = Integer.rotateLeft(a, shifts); System.out.println(a); shifts++; } int b = "61"; int shifts2 = 0; while (shifts2 < 2) { b = Integer.rotateLeft(b, shifts2); System.out.println(b); shifts2++; } } } Output: prog.java:9: error: incompatible types: possible lossy conversion from double to int int a = 15.71; ^ prog.java:18: error: incompatible types: String cannot be converted to int int b = "61"; ^ 2 errors Comment More infoAdvertise with us Next Article Integer rotateLeft() Method in Java ankita_chowrasia Follow Improve Article Tags : Java Java-lang package Java-Functions Java-Integer Practice Tags : Java Similar Reads Integer rotateRight() Method in Java Bit shifting is used in programming and has at least one variation in each programming language. Java has a single Logical right shift operator (>>). Bit shifting is a type of bitwise operation. Bit shifting is done on all the bits of a binary value which moves the bits by a definite number of 2 min read Integer shortValue() Method in Java The Integer.shortValue() is an inbuilt method of java.lang which returns the value of this Integer in the short type . Syntax: public short shortValue() Parameters: The method does not take any parameters. Return Value: The method returns the integer value represented by this object after converting 2 min read Integer reverse() Method In Java The java.lang.Integer.reverse() is an inbuilt method in Java and is used to return the reverse order of the bits in the two's complement binary representation of the specified int value. Syntax: public static int reverse(int a) Parameters: The parameter a is an integer value whose bits are to be rev 2 min read Integer toOctalString() Method in Java Octal is the base-8 number system and uses the digits 0 to 7 in operation. Octal is widely used in computing on systems like the PDP-8, and IBM mainframes employed 12-bit, 24-bit or 36-bit words. The Java.lang.Integer.toOctalString() method is a built-in function in Java that is used to return a str 3 min read Integer reverseBytes() Method in Java The java.lang.Integer.reverseBytes(int a) is a built-in method which returns the value obtained by reversing the order of the bytes in the two's complement representation of the specified int value. Syntax : public static int reverseBytes(int a) Parameter: The method takes one parameter a of integer 3 min read Integer sum() Method in Java The java.lang.Integer.sum() is a built-in method in java that returns the sum of its arguments. The method adds two integers together as per the + operator. Syntax : public static int sum(int a, int b) Parameter: The method accepts two parameters that are to be added with each other: a : the first i 2 min read BigInteger shiftLeft() Method in Java The java.math.BigInteger.shiftLeft(int n) method returns a BigInteger whose value is (this << n). The shift distance, n, may be negative, in which case this method performs a right shift.shiftLeft() method will moves each digit in a number's binary representation left by n times and the last b 2 min read Integer signum() Method in Java The signum function is an odd mathematical function that extracts the sign of a real number. The signum function is also known as sign function. The Integer.signum() method of java.lang returns the signum function of the specified integer value. For a positive value, a negative value and zero the me 3 min read BigInteger setBit() Method in Java The java.math.BigInteger.setbit(index) method returns a Big-integer whose value is equivalent to this Big-integer with the designated bit set. The method computes (this | (1<<n)). The bit at index n of binary representation of Big-integer will be set means converted to 1. Syntax: public BigInt 2 min read Integer intValue() Method in Java intValue() of Integer class that is present inside java.lang package is an inbuilt method in java that returns the value of this integer as an int which is inherited from Number Class. The package view is as follows: --> java.lang Package --> Integer Class --> intValue() Method Syntax: publ 3 min read Like