posts - 93,  comments - 2,  trackbacks - 0
          1.字節(jié)數(shù)組取反
          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.查找字節(jié)數(shù)組中字?jǐn)?shù)組的位置
          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.字節(jié)數(shù)組轉(zhuǎn)換為16進(jìn)制

          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) 評(píng)論(0)  編輯  收藏 所屬分類: Tomcat+Eclipse
          <2013年12月>
          24252627282930
          1234567
          891011121314
          15161718192021
          22232425262728
          2930311234

          常用鏈接

          留言簿(2)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          相冊(cè)

          收藏夾

          Java

          搜索

          •  

          最新隨筆

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 鄂托克旗| 西林县| 涡阳县| 陕西省| 潮安县| 鸡东县| 广平县| 塘沽区| 句容市| 垫江县| 汪清县| 江都市| 包头市| 桦南县| 醴陵市| 万盛区| 盈江县| 新源县| 三河市| 白河县| 韶关市| 松江区| 凌源市| 湄潭县| 九江县| 隆尧县| 衡东县| 迁西县| 全州县| 宿迁市| 临朐县| 乐亭县| 濮阳县| 敦煌市| 安福县| 巴东县| 天峨县| 故城县| 忻州市| 夏津县| 凤凰县|