天天看点

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

继续阅读