×

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 : 1
Example 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 : 0
Example 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 : 1
Example 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

Related Topics

JDBC Program in Java

JDBC Program in Java JDBC is an API that defines how a client may access a database. It is a part of Java Standard Edition (Java SE). JDBC stands for Java...

4 minutes read.

Java Math floor() Method

The floor() method of Math class returns the largest double value that is equal to a mathematical integer and is less than or equal to the argument. Syntax: public static double floor(double...

2 minutes read.

Java Transient

Java Transient In Java, Serialization is used to convert an object into a stream of the byte. The byte stream consists of the data of the instance as well as the...

3 minutes read.

Process and Thread in Java

Process It is a program that is running on your computer. The process is a heavy-weight, which takes memory separately to other processes. The process may be a small background task like spell-checker; it...

11 minutes read.

How to Convert String to Integer in Java

How to convert String to int in Java You need to convert String into int if you want to perform a mathematical operation on string which contains digits. To do so,...

3 minutes read.

How to Iterate a HashMap in Java?

Hash-map is a class of Java collections framework which has the functionality to implement the Map interface of Java. It stores the data in key-value pairs and can be accessed...

5 minutes read.

Java 9 Interface Private Method

Java 9 provides us the facility to include private methods inside the java interface. In java 8 and earlier versions, we are supposed to use only constant variables and abstract...

3 minutes read.

Java Abstraction

Java Abstraction Abstraction is an advanced feature of Java to make it transparent. The main motive behind the abstraction is to deal with ideas, not with events. Abstraction is a process...

4 minutes read.

Java OCR

In this article, you will be acknowledged about what is a tesseract OCR, how it works, what are its used and advantages and disadvantages. Also, you will be able to...

4 minutes read.

Java Append Data to File

When writing data to a file using the classes within the java.io package, its file will often be overwritten, meaning that any existing data will be removed and new data...

4 minutes read.

Vector in Java

Java Vector Class The Vector class is a legacy class that implements a growable array of objects. The components that it contains can be accessed using an integer index. The size of...

26 minutes read.

Compare time in java

Introduction: This article discusses how to compare time in java. Maximum of the time we need to examine the date and datetime items. Date comparisons are vital if you want to...

3 minutes read.

How to find length of integer in Java

We can find the length of the integer in many ways. The length of an integer is defined as the count of the number of digits for the given integer. These...

5 minutes read.

Buffer reader to read string in Java

The Buffered Reader class of Java is used to read the stream of characters from the input stream. Program to read string using Buffer reader import java.io.*; class  Demo {   public static void main(String...

3 minutes read.

Collection Interfaces in Java with Examples

In this tutorial, we will discuss collection interfaces in Java with Examples. Introduction The Collection Interface is an individual from the Java Collections Framework. It is a root point of interaction of...

4 minutes read.

Math fma () method in java

In java, the Math module constitutes of fma () Method in it. This method can be accessed in two ways which can be differentiated by the parameters which are given...

4 minutes read.

Java Comparator Interface

Java comparator interface is used in a situation when we have to sort an object which does not implement Comparable or do sorting in a different way than the Comparable....

1 minute read.

Methods in Java

The Methods in Java are the collection of statements that are executed when the method is called. By using the methods, the complexity of writing the code decreases. The method consists...

4 minutes read.

Set Value to Enum in Java

In this article, you will be acknowledged about Enum in java. Most importantly you will learn how to set value to Enum or how to practically customize a value to...

3 minutes read.

Rotate matrix by 90 degrees in Java | Rotate matrix in Java clockwise and anti-clockwise

In this article, you will be acknowledged about what is a matrix along with an example. Most importantly you will be equipped knowledge on how to rotate the matrix by...

4 minutes read.