Java Integer.lowestOneBit(int i) example

Java Integer.lowestOneBit(int i) example

By Yashwant Chavan, Views 5, Date 21-Apr-2018

In this java tutorial, You will learn how to use lowestOneBit(int i) method of class Integer. This 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.

tags Java

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.

Syntax

public static int lowestOneBit(int i)

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.

Java Integer lowestOneBit(int i) example

  • Assign two integer values.
  • Integer.lowestOneBit(firstValue);It will return the lowest one bit of firstValue.
  • Integer.lowestOneBit(secondValue);It will return the lowest one bit of secondValue.
  • Print the values.
package com.technicalkeeda;

public class App {

    public static void main(String[] args) {

        Integer firstValue = 125;
        Integer secondValue = 42;

        int result1 = Integer.lowestOneBit(firstValue);
        int result2 = Integer.lowestOneBit(secondValue);

        System.out.println("Lowest one bit of firstValue :- " + result1);
        System.out.println("Lowest one bit of secondValue :- " + result2);
    }
}

output

Lowest one bit of firstValue :- 1
Lowest one bit of secondValue :- 2
Yashwant

Yashwant

Hi there! I am founder of technicalkeeda.com and programming enthusiast. My skills includes Java,J2EE, Spring Framework, Nodejs, PHP and lot more. If you have any idea that you would want me to develop? Lets connect: yashwantchavan[at][gmail.com]