Java.lang Package Classes

Java Integer - lowestOneBit() Method



The java.lang.Integer.lowestOneBit() method returns an int value with at most a single one-bit, in the position of the lowest-order ("rightmost") one-bit in the specified int value. Returns zero if the specified value has no one-bits in its two's complement binary representation, that is, if it is equal to zero.

Syntax

public static int lowestOneBit(int i)

Parameters

i Specify the value whose lowest one bit is to be computed.

Return Value

Returns an int value with a single one-bit, in the position of the lowest-order one-bit in the specified value, or zero if the specified value is itself equal to zero.

Exception

NA.

Example:

In the example below, the java.lang.Integer.lowestOneBit() method returns an int value with a single one-bit, in the position of the lowest-order one-bit in the specified value.

import java.lang.*;

public class MyClass {
  public static void main(String[] args) {
    
    //creating int value
    int x = 120;

    //printing x
    System.out.println("The x is = " + x);     

    //printing the binary representation of x
    System.out.println("The x in binary is = " + Integer.toBinaryString(x)); 

    //printing the lowest-order one-bit
    System.out.println("Lowest-order one-bit = " + Integer.lowestOneBit(x)); 
  }
}

The output of the above code will be:

The x is = 120
The x in binary is = 1111000
Lowest-order one-bit = 8

❮ Java.lang - Integer

5