码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2017-08-18 15:23:13      阅读:122      评论:0      收藏:0      [点我收藏+]

标签:integer   style   sys   print   数值   byte   string   pre   color   

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);

 

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

标签:integer   style   sys   print   数值   byte   string   pre   color   

原文地址:http://www.cnblogs.com/tonggc1668/p/7389616.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!