天天看點

byte取高4位,低4位,byte轉int

byte abyte =-1;         System.out.println(abyte);         System.out.println(Integer.toBinaryString(abyte));         //取高四位         byte high = (byte) ((abyte>>4) & 0x0f);         System.out.println("取高四位"+Integer.toBinaryString(high));         //取低四位         byte low =  (byte) (abyte & 0x0f);         System.out.println("取低四位"+Integer.toBinaryString(low));         //byte轉int保持數值不變         int b= (int)abyte;         System.out.println(b);         //byte轉int保持最低位元組中各個位不變         int c= (int)(abyte & 0xff);         System.out.println(c);      

-1

11111111111111111111111111111111

取高四位1111

取低四位1111

255

繼續閱讀