java.lang.Integer highestOneBit(int i)

Description :

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

Method Syntax :

public static int highestOneBit(int i)

Parameter Input :

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

Method Returns :

The highestOneBit(int i) method simply returns the int value with a single one-bit, in the position of the highest-order one-bit in the specified value, or zero if the specified value is itself equal to zer0

Compatibility Version :

Requires Java 1.5 and up

Exception :

N/A

Java Code Example :

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

package com.javatutorialhq.java.examples;

import static java.lang.System.*;

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

public class IntegerHighestOneBit {

	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 highest one's bit
		out.println("Highest one's but equivalent:"+Integer.highestOneBit(value));

	}

}

Sample Output :

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

Binary equivalent:10110010
Highest one's but equivalent:128

Exception Scenario :

N/A

Similar Method :

  • N/A

Suggested Reading List :

References :