Java Integer lowestOneBit()
The lowestOneBit () method of Java Integer class returns an int value with at most a single one-bit, in the position of the lowest-order one-bit in the specified int value. Syntax public static int lowestOneBit(int i) Parameters The parameter ‘i’ represents the value whose lowest one bit is to be calculated. Return Value This method returns an int value with a single one-bit in the lowest-order position. Example 1
public class JavaIntegerLowestOneBitExample1 { public static void main(String[] args) { Integer a=234; Integer b=67; //returns an int value with at most a single one-bit, in the position of the lowest-order one-bit int val=Integer.lowestOneBit(a); System.out.println("Lowest one bit of "+a+" : "+val); System.out.println("Lowest one bit of "+b+" : "+Integer.lowestOneBit(b)); } }Output
Lowest one bit of 234 : 2 Lowest one bit of 67 : 1Example 2
public class JavaIntegerLowestOneBitExample2 { public static void main(String[] args) { Integer a=-0; //returns 0 if the integer value passed is zero int val=Integer.lowestOneBit(a); System.out.println("Lowest one bit of "+a+" : "+val); } }Output
Highest one bit of 0 : 0Example 3
public class JavaIntegerLowestOneBitExample3 { public static void main(String[] args) { Integer a=Integer.MAX_VALUE; //returns 1 if the integer value passed is MAX_Value int val=Integer.lowestOneBit(a); System.out.println("Lowest one bit of "+a+" : "+val); } }Output
Lowest one bit of 2147483647 : 1Example 4
public class JavaIntegerLowestOneBitExample4 { public static void main(String[] args) { Integer a=Integer.MIN_VALUE; //returns the min one- bit value if the integer value passed is MAX_Value int val=Integer.lowestOneBit(a); System.out.println("Lowest one bit of "+a+" : "+val); } }Output
Lowest one bit of -2147483648 : -2147483648