×

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

Command Class in Java

We use the command class to run commands against the database. The Command class may find a set of parameter objects for use in sending values to a stored procedure...

3 minutes read.

Race Condition in Java

Java is a multi-threaded programming language, race conditions are more likely to arise. Mostly because data can change when multiple threads visit the same resource simultaneously. Race conditions are concurrency...

3 minutes read.

Pangram Program in Java

If a string comprises all alphabet letters from A to Z or from a to z without regard to case, it is referred to as a pangram. Some examples of pangram...

3 minutes read.

Check whether a Number is a Power of 4 or Not in Java

There are many ways to figure out if an integer is a power of 4. This section will go over a variety of techniques for figuring out whether or not...

11 minutes read.

Advantages of Generics in Java

Generic offers a variety of benefits. The programmer's life is made easier by using generic Java. In this section, we are going to discuss about Java's generic’s and its benefits. 1....

4 minutes read.

How to handle NullPointerException in Java

Introduction: Throwable class is the super or root class of the java exception hierarchy which contains two sub-classes. The classes’ are- ExceptionError Exception: If you are doing any wrong things in a...

3 minutes read.

Java Math getExponent() Method

The getExponent() method of Math class returns the unbiased exponent of the argument. Syntax: public static int getExponent (double d) Parameters: The parameter ‘d’ represents the double value. Return Value: The getExponent () method returns the...

1 minute read.

Java Long Keyword

Long is a primitive data type in Java. To initilize variables, we implement the long keyword. It can also be applied to techniques. A 64-bit two's complement integer can put...

3 minutes read.

Display Unique Rows in a Binary Matrix in Java

To solve this problem, we must first locate and display the distinct rows of a supplied binary matrix afterward. We will go through how to show distinct rows inside a...

12 minutes read.

Java String toUpperCase() methods

Java String toUpperCase() method is used to convert all the characters of the String into upper case. Syntax public String toUpperCase() public String toUpperCase(Locale locale) Returns It returns upper case String. Java String toUpperCase() Example 1: public...

1 minute read.

Longest Odd Even Subsequence in Java

In order to solve the Java problem known as the longest odd-even subsequence, one must identify a sequences in a non-negative array having size s that alternately includes odd and...

6 minutes read.

Median Of Stream Of Running Integers in Java

An integer array is given to us. Compute the median of the elements traversed so far in the input array. For the sake of simplicity, assume that there are no...

10 minutes read.

Difference between Constructor and Method in Java

What is Constructor? In Constructor, we will discuss constructors and also will discuss default constructors and finally, we will discuss overloading constructors. A constructor is a method that is used to...

13 minutes read.

Java Enum

Enumerations are used in programming languages to represent collections of named constants. For instance, the four suits in a deck of playing cards might represent four iterators named Club, Diamond,...

3 minutes read.

Reverse a String using Collections in Java

Generally, a String is a grouping of characters. Yet, in Java, a String is an item that addresses a succession of characters. The Java.lang.String class is utilized to make a...

5 minutes read.

Constructor Overloading in Java

In Java, constructors can be overloaded just like methods. The idea of having multiple constructors with various parameter sets so that each function Object()  can carry out a particular task...

3 minutes read.

Reserved Keywords in Java

In Java, a reserved term is used as a code key called a keyword. Because they are predefined, these terms cannot be used for anything else. They cannot serve as...

3 minutes read.

Compile time vs Runtime in java

Introduction: This article will discuss compile time vs. runtime in java. Compile time and runtime are two programming terms utilized in software improvement. Compile time is when the source code is...

3 minutes read.

Bean class in Java

The web applications that are created with the help of the JSP or Java Server Pages generally have fairly more functionality than the web pages that specifically are created with...

5 minutes read.

Java Tokens

Classes and methods are included in the Java program. The procedures also provide the expressions and statements required to finish a specific operation. Tokens make up the sentences and expressions...

4 minutes read.