Bit oriented operation
static int bitCount(int i)
- Count the bits
static int highestOneBit(int i)
- Returns an int value with at most a single one-bit, in the position of the highest-order ("leftmost") one-bit.
static int lowestOneBit(int i)
- Returns an int value with at most a single one-bit, in the position of the lowest-order ("rightmost") one-bit.
public class Main {
public static void main(String[] args) {
System.out.println(Integer.bitCount(10));
System.out.println(Integer.highestOneBit(10));
System.out.println(Integer.lowestOneBit(10));
}
}
The output:
2
8
2
Home
Java Book
Essential Classes
Java Book
Essential Classes
Integer:
- Integer class
- Max, min value of an integer type variable
- Create Integer using its constructors
- Return an integer value as byte, double, float, int, long and short
- Compare two integer values
- Decode a string and return an integer value
- Convert string to integer
- Convert integer to string
- Reverse and rotate the integer in binary format
- Bit oriented operation
- Return system property as integer
- Get the leading and trailing zeros
- Get the sign of an Integer
- Convert integer to binary, hexdecimal and octal format