我们知道:int型值占4个字节,32bit。
权值 | Math.pow(2, 31) | …… | Math.pow(2, n-1) | …… | 8 | 4 | 2 | 1 |
Bit位数 | n=32 | …… | n | …… | 4 | 3 | 2 | 1 |
下面这段代码清楚的告诉了我们方法:
private boolean isIntNumberNBitONEInBinary(int number,int nbit){
boolean result = false;
if((number%(Math.pow(2, nbit)))/(Math.pow(2, nbit-1)) >= 1.0){
result = true;
}
return result;
}