<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆-77  評論-5  文章-2  trackbacks-0

     

    public class Util {
     final static int LINE_COUNT = 16;
     final static int WORD_COUNT = 2;
     public static StringBuffer toHex(byte b)
     {
      byte factor = 16;
      int v = b & 0xff;//去掉byte轉(zhuǎn)換之后的負(fù)數(shù)部分。
      byte high = (byte)( v / factor);
      byte low = (byte)(v % factor);
      StringBuffer buf = new StringBuffer();
      buf.append(toHexLow(high)).append(toHexLow(low));
      return buf;
     }
     private static char toHexLow(byte b)
     {
      if(b > 16 || b < 0 )
      {
       throw new IllegalArgumentException("inpt parameter should less than 16 and greater than 0");
      }
      if(b < 10){
       return (char)('0' + (char)b);
      }
      else{
        return (char)('A' + (b-10));

      }
     }
     
     public static StringBuffer toHex(int val)
     {
      StringBuffer buf = toHex((byte)(val >>24 & 0xff)).append(toHex((byte)(val>>16&0xff)));
      return buf.append(toHex((byte)(val>>8&0xff))).append(toHex((byte)(val & 0xff)));
     }
     
     /**
      * 打印二進(jìn)制數(shù)組
      * @param arr
      * @param off
      * @param len
      */
     public static void printBytes(byte [] arr,int off,int len)
     {
      if(arr == null || len <= 0 || off <0 || off + len > arr.length){
       return;
      }
      
      int count = 0;
      
      for(int i = off; count < len; ++i)
      {
       System.out.print(toHex(arr[i]));
       
       ++ count;
       if(count% WORD_COUNT == 0)
       {
        System.out.print(' ');
       }
       if(count % LINE_COUNT == 0)
       {
        System.out.println();
       }
      }
     }
     
     public static void main(String[] args) {
      byte[] arr = new byte[256];
      for(int i = 0; i < 256;++i )
      {
       
       arr[i] = (byte)i;
       
      }
      
      printBytes(arr,0,256);
      printBytes(arr,240,16);
      
      System.out.println(toHex(1));
      System.out.println(toHex(0xffffffff));
      System.out.println(toHex(0xeeffaacc));
     }
    }




    另外c++寫好的小端序的int數(shù)據(jù),用java讀入如此處理
     private static int convertInt(byte[]  arr)
     {
      if(arr == null || arr.length != 4)
      {
       throw new IllegalArgumentException("bytes array error");
      }
      int val = (arr[0] & 0xff) | (arr[1] & 0xff)<<8 | (arr[2] & 0xff)<<16 | (arr[3]&0xff)<<24;
      return val;
     }


    posted on 2011-11-02 21:36 huohuo 閱讀(5403) 評論(0)  編輯  收藏

    只有注冊用戶登錄后才能發(fā)表評論。


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 亚洲乱码日产精品a级毛片久久| 男人j进女人p免费视频| 久久夜色精品国产亚洲AV动态图| 久久久久亚洲AV成人网人人网站| 国产亚洲日韩一区二区三区| 亚洲天天做日日做天天看| 国产精品亚洲精品青青青| 久久亚洲欧美国产精品| 中文字幕不卡免费视频| 午夜视频免费在线观看| 国产一二三四区乱码免费| 九九久久国产精品免费热6| 你懂的在线免费观看| 亚洲综合国产精品第一页| 亚洲毛片αv无线播放一区| 亚洲精品少妇30p| 91嫩草亚洲精品| 亚洲一区免费观看| 亚洲AV第一成肉网| 黄色三级三级三级免费看| 精品久久久久久久久亚洲偷窥女厕| 国产成人va亚洲电影| 亚洲精品无码av天堂| 亚洲综合久久夜AV | 亚洲乱码日产精品BD在线观看| 午夜国产精品免费观看| 亚洲一本大道无码av天堂| 99久久免费国产精品热| 亚洲四虎永久在线播放| 成人免费无码视频在线网站| 国产精品xxxx国产喷水亚洲国产精品无码久久一区 | 国产成人麻豆亚洲综合无码精品| 免费91最新地址永久入口 | 免费视频淫片aa毛片| 亚洲成人激情在线| 青苹果乐园免费高清在线| 青娱乐在线免费观看视频| 亚洲av激情无码专区在线播放| 国产福利在线观看免费第一福利| 亚洲国产精品久久久久婷婷软件 | 国产免费黄色大片|