常用

</pre><pre name="code" class="java">
<pre name="code" class="java">

public String intToIp(int i) {     
   
//   return ((i >> 24 ) & 0xFF ) + "." +     
//               ((i >> 16 ) & 0xFF) + "." +     
//               ((i >> 8 ) & 0xFF) + "." +     
//               ( i & 0xFF) ;     
  
return ((i & 0xff)+"."+(i>>8 & 0xff)+"."  
                +(i>>16 & 0xff)+"."+(i>>24 & 0xff));
}
 

public static int counter(String s,char c){
<span style="white-space:pre">		</span>  int count=0;
<span style="white-space:pre">		</span>  for(int i=0;i<s.length();i++){
<span style="white-space:pre">		</span>   if(s.charAt(i)==c){
<span style="white-space:pre">		</span>    count++;
<span style="white-space:pre">		</span>   }
<span style="white-space:pre">		</span>  }
<span style="white-space:pre">		</span>  return count;
<span style="white-space:pre">		</span> }

public static byte[] charToByte(char c) {
        byte[] b = new byte[2];  
        b[0] = (byte) (c >>> 8);  
        b[1] = (byte) c;  
        return b;  
}

public static char bytesToChar(byte[] b) {  
        char c = (char) ((b[0] << 8) & 0xFF00L);  
        c |= (char) (b[1] & 0xFFL);  
        return c;  
    }

public long getlongFromByte(byte[] bt, int nstart){
<span style="white-space:pre">		</span>long sum = 0;
<span style="white-space:pre">		</span>for(int i = 0; i<8; i++){
<span style="white-space:pre">			</span>long temp = ((long) bt[i+nstart] )&0xff;      
<span style="white-space:pre">	</span>           temp <<= i*8;
<span style="white-space:pre">	</span>           sum += temp;
<span style="white-space:pre">		</span>}
<span style="white-space:pre">		</span>return sum;
<span style="white-space:pre">	</span>}

public  static int getIntFromByte(byte[] bytearray, int nstart)
    {
<span style="white-space:pre">		</span>int sum = 0;
       for (int i = 0 ; i <4 ; i++)
       {
           int temp =((int) bytearray[i+nstart] )&0xff;
          
           temp <<= i*8;
           sum = temp + sum;   
       }
       return sum;
     }
public static byte[] byteMerger(byte[] byte_1, byte[] byte_2){  
        byte[] byte_3 = new byte[byte_1.length+byte_2.length];  
        System.arraycopy(byte_1, 0, byte_3, 0, byte_1.length);  
        System.arraycopy(byte_2, 0, byte_3, byte_1.length, byte_2.length);  
        return byte_3;  
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值