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
-1
255

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-09-05
  • 2021-12-13
  • 2022-01-10
  • 2022-12-23
  • 2021-09-09
猜你喜欢
  • 2021-05-06
  • 2021-12-19
  • 2022-12-23
  • 2022-01-11
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案