posts - 93,  comments - 2,  trackbacks - 0
          1.字節數組取反
          public static byte[] backByte(byte[] buff){
            
          for (int i=0;i<buff.length;i++){
                      
          int b=0;
                      
          for (int j=0;j<8;j++){
                          
          int bit = (buff[i]>>j&1)==0?1:0;
                          b 
          += (1<<j)*bit;
                      }

                      buff[i]
          =(byte)b;
                  }

            
          return buff;
           }
           

          2.查找字節數組中字數組的位置
          public static int indexOf(byte[] src,int offset,byte[] needFind){
                  
          for(int i=offset;i<src.length-offset-needFind.length;i++){
                      
          boolean isValid=true;
                      
          for(int j=0;j<needFind.length;j++){
                          
          if(src[i+j]!=needFind[j]){
                              isValid
          =false;
                              
          break;
                          }

                      }

                      
          if(isValid){
                          
          return i;
                      }

                  }

                  
          return -1;
              }



          3.字節數組轉換為16進制

          private static final byte[] HEX_CHAR_TABLE = { (byte) '0', (byte) '1',
          (
          byte) '2', (byte) '3', (byte) '4', (byte) '5', (byte) '6',
          (
          byte) '7', (byte) '8', (byte) '9', (byte) 'A', (byte) 'B',
          (
          byte) 'C', (byte) 'D', (byte) 'E', (byte) 'F' }
          ;

          public static String getHexString(byte[] raw, int len) {
          byte[] hex = new byte[2 * len];
          int index = 0;
          int pos = 0;
          for (byte b : raw) {
          if (pos >= len)
          break;
          pos
          ++;
          int v = b & 0xFF;
          hex[index
          ++] = HEX_CHAR_TABLE[v >>> 4];
          hex[index
          ++] = HEX_CHAR_TABLE[v & 0xF];
          }


          return new String(hex);
          }



          posted on 2013-12-25 11:32 Terry Zou 閱讀(729) 評論(0)  編輯  收藏 所屬分類: Tomcat+Eclipse
          <2013年12月>
          24252627282930
          1234567
          891011121314
          15161718192021
          22232425262728
          2930311234

          常用鏈接

          留言簿(2)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          相冊

          收藏夾

          Java

          搜索

          •  

          最新隨筆

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 喀喇沁旗| 巨野县| 辽宁省| 岳西县| 重庆市| 上饶市| 北流市| 扶余县| 桐乡市| 梅州市| 保靖县| 攀枝花市| 益阳市| 湘乡市| 佛坪县| 巢湖市| 金乡县| 蒙自县| 康乐县| 丁青县| 汽车| 民丰县| 那曲县| 绥宁县| 洞头县| 阜新| 西林县| 北宁市| 象州县| 阿勒泰市| 从江县| 根河市| 岗巴县| 忻州市| 获嘉县| 鱼台县| 东兰县| 通山县| 海晏县| 普陀区| 竹北市|