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

          搜索

          •  

          最新隨筆

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 万荣县| 曲麻莱县| 澄城县| 九江市| 广西| 定兴县| 巨野县| 汤阴县| 天气| 呼和浩特市| 高台县| 安塞县| 家居| 读书| 四子王旗| 静安区| 乌兰浩特市| 吐鲁番市| 五大连池市| 濉溪县| 三明市| 高尔夫| 百色市| 泸定县| 鄂托克旗| 新营市| 广南县| 福建省| 卓资县| 民权县| 米泉市| 横峰县| 九寨沟县| 绥芬河市| 佛学| 东城区| 辽阳县| 长兴县| 湄潭县| 万宁市| 万州区|