基本數據類型中不經常使用的方法

Byte b = 8;
Byte t3 = Byte.valueOf("167", b);//把3進制的22轉成10進制的8    即  64+48+7=119it

int in3 = b.compareTo(t3);//兩個Byte類型的數字比較(b-t3),差值返回int類型 -111
class

 

Short s = 1;二進制

Short ss = Short.reverseBytes(s);//方法返回的值是獲得2的補碼錶示指定的字節的順序顛倒過來的short值。獲得的結果是原來的256倍即s*256方法

 

 

Integer i = 0;
int r = Integer.highestOneBit(i); //i位負數則結果爲-2147483648  i=0則結果爲0 i爲正數則結果爲i與K=2*2^n(n=0,1,2...)最接近的數值K,i>=K?K:(K/2)di

JDK的解析:co

返回具備至多單個 1 位的 int 值,在指定的 int 值中最高位(最左邊)的 1 位的位置。若是指定的值在其二進制補碼錶示形式中不具備 1 位,即它等於零,則返回零。數字

int l =Integer.lowestOneBit(i);

int l=Integer.numberOfLeadingZeros(i);

int l=Integer.numberOfTrailingZeros(i);

int l=Integer.bitCount(i);

int l=Integer.rotateLeft(i);

int l=Integer.rotateRight(i);

int l=Integer.reverse(i);

相關文章
相關標籤/搜索