</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;
}