×

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

Stack Program in Java

Stack Program in Java The Stack class is part of the collection framework that inherits the Vector class. Thus, the Stack class can also be called a subclass of the Vector...

5 minutes read.

Java array list remove time complexity

Java: We know that java is one of the programming languages. The main feature of java which is not in C or object oriented programming language is platform independence. Not only the...

7 minutes read.

Java InputStreamReader

What is InputStreamReader?An InputStreamReader is a converter between byte and character streams: It reads bytes and converts them to characters with the help of a charset. The charset it uses can...

4 minutes read.

How to Convert String to char in Java

How to Convert String to char in Java There are two methods to convert String to char are: Using charAt() method Using tocharArray() method Using charAt() method This is the method of String class that...

3 minutes read.

Pattern Programs in Java

Pattern Programs in Java In Java, pattern programs are the most important from the perspective of interviews. The pattern programs improve thinking and coding skills. It also helps us to develop a...

27 minutes read.

Graph Problems in Java

A graph is a special type of data structure used in programming that is made up of edges connecting each set of finitely many nodes, or vertices, to each other....

14 minutes read.

MessageDigest in Java

The compression of mathematical numbers is accomplished using hash functions. In almost every data security application, hash functions are employed. The hashing, often called has values, returns a value called...

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.

Program to find and replace characters on string in java

In JAVA, Strings are immutable. To overcome this Java String class contains a lot of methods to do operations on Strings. One such method is replace method. String Replace It returns a...

3 minutes read.

GCD Program in Java

GCD Program in Java The GCD program in Java outputs the GCD of the given numbers. In mathematics, Greatest Common Divisor (GCD), Greatest Common Factor or Highest Common Factor (HCF) of...

14 minutes read.

Read the XLSX file in Java

Excel files contain cells; reading an excel file in Java differs from reading a word file. JDK doesn't have a direct API that can read or write Word or Excel...

3 minutes read.

Java Strings

String class is the most used class in Java programming language. The string is the sequence of characters, which is treated as objects in Java. Creating String objects We create String objects...

5 minutes read.

Conditional operator in Java

In Java, there are around eight operators, and among them, three operators are used to evaluate the condition and decide the Result based on the Result of the evaluated condition. Below...

4 minutes read.

String isnullorempty in Java

What do you mean by String? Strings are a collection of characters that are commonly used in Java programming. Strings are regarded as objects in the Java programming language. “String” is a...

4 minutes read.

Concurrent Linked Deque in Java with Examples

Introduction Java's concurrent-linked deque, which holds its items as linked nodes, is unconstrained and thread-safe. Concurrent Linked Deque allows for element removal and addition on both sides because it implements the...

4 minutes read.

String Manipulation in Java

String Manipulation in Java In Java, string manipulation is a common task performed by programmer. Java String class provides many built-in functions that are used to manipulate string. The manipulation of...

4 minutes read.

The final Keyword in Java

The final keyword is employed in several instances. Firstly, the non-access modifier final only applies to variables, methods, and classes. The final can be used in the following situations. Final Variables When...

6 minutes read.

Java this keyword

This Keyword in Java This keyword can be used in many different ways in Java. This is a reference variable in Java that points to the active object. In Java, the...

8 minutes read.

Java exception list

Java uses exceptions, like the majority of contemporary programming languages, to deal with both errors and "extraordinary events." When an exception arises inside the program, it messes up the regular...

6 minutes read.

String Handling Method in Java

What is a String? Strings are a bundle of different characters that are normally used in Java programming language. Strings are regarded as objects in the Java programming language. “String” is a...

4 minutes read.