Java Integer lowestOneBit()方法
java.lang.Integer.lowestOneBit() 方法在指定的int值返回一个int值最多单个1位,在最低阶(“最右”)1位的位置。它返回零,如果指定的值没有一个位在其二进制补码表示法,即,如果它等于零。
1 语法
public static int lowestOneBit(int i)
2 参数
i : 这是int值。
3 返回值
此方法返回一个int值和单个1位,在指定的值最低阶1位的位置,或者零,如果指定值本身等于零。
4 示例
package com.yiidian;
/**
* 一点教程网: http://www.yiidian.com
*/
/**
* Java Integer lowestOneBit()方法
*/
import java.lang.*;
public class IntegerDemo {
public static void main(String[] args) {
int i = 170;
System.out.println("Number = " + i);
/* returns the string representation of the unsigned integer value
represented by the argument in binary (base 2) */
System.out.println("Binary = " + Integer.toBinaryString(i));
// returns the number of one-bits
System.out.println("Number of one bits = " + Integer.bitCount(i));
/* returns an int value with at most a single one-bit, in the position
of the highest-order ("leftmost") one-bit in the specified int value */
System.out.println("Highest one bit = " + Integer.highestOneBit(i));
/* 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.*/
System.out.println("Lowest one bit = " + Integer.lowestOneBit(i));
}
}
输出结果为:
Number = 170
Binary = 10101010
Number of one bits = 4
Highest one bit = 128
Lowest one bit = 2