java.lang.Integer lowestOneBit(int i)

Description :

This java tutorial shows how to use the lowestOneBit() method of Integer class under java.lang package. This method return the int equivalent of the lowest bit order (right most part) of the binary equivalent of the int method argument.

Method Syntax :

public static int lowestOneBit(int i)

Parameter Input :

DataType Parameter Description
int i the integer value that we want to get the Integer equivalent of the lowest 0ne's bit.

Method Returns :

The lowestOneBit(int i) method simply 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.

Compatibility Version :

Requires Java 1.5 and up

Exception :

N/A

Java Code Example :

This java example source code demonstrates the use of lowestOneBit(int i) method of Integer class.

package com.javatutorialhq.java.examples;

import static java.lang.System.*;

/*
 * This example source code demonstrates 
 * the use of lowestOneBit method of Integer class
 */

public class IntegerLowestOneBit {

	public static void main(String[] args) {
		int value = 178;
		// Get the binary equivalent
		out.println("Binary equivalent:"+Integer.toBinaryString(value));
		// get the integer equivalent of the lowest one's bit
		out.println("Lowest one's bit equivalent:"+Integer.lowestOneBit(value));

	}

}

Sample Output :

Running the lowestOneBit(int i) method example source code of Integer class will give you the following output

Binary equivalent:10110010
Lowest one's bit equivalent:2

Exception Scenario :

N/A

Similar Method :

  • N/A

Suggested Reading List :

References :