## Tuesday, October 11, 2011

### Implementation of Checksum Calculation using java program

Implementation of Checksum Calculation using java program

Implementation of Checksum Calculation using java program

package com.gnec;
import java.lang.Math;
public class Checksum2 {

/**
* @param args
*/
public static void main(String[] args)throws Exception {
// TODO Auto-generated method stub
//int td[][]=new int[14][16];
System.out.println(".......WELCOME TO CHECKSUM CALCULATION........");
int td[][]={{1,0,0,1,1,0,0,1,0,0,0,1,0,0,1,0},
{0,0,0,0,1,0,0,0,0,1,1,0,1,0,0,1},
{1,0,1,0,1,0,1,1,0,0,0,0,0,0,1,0},
{0,0,0,0,1,1,1,0,0,0,0,0,1,0,1,0},
{0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1},
{0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1},
{0,0,0,0,0,1,0,0,0,0,1,1,1,1,1,1},
{0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,1},
{0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,1,0,1,0,1,0,0,0,1,0,0,0,1,0,1},
{0,1,0,1,0,0,1,1,0,1,0,1,0,1,0,0},
{0,1,0,0,1,0,0,1,0,1,0,0,1,1,1,0},
{0,1,0,0,0,1,1,1,0,0,0,0,0,0,0,0}
};

int sum=0;
for(int i=0;i<14;i++)
{
int temp[]=new int[16];

for(int j=0;j<16;j++)
{
temp[j]=td[i][j];
}
int x=15;
int deci=0;
for(int j=0;j<16;j++)
{
double d=x;
double t=2.0;
double d2= Math.pow(t,d);
deci=deci+(temp[j]* (int)d2);
x--;

}
sum=(sum+deci)%65535;

}
int csum=65535-sum,i=0;
int stemp[]=new int[16];
System.out.println("The checksum in decimal is="+(65535-sum));
while(csum!=0)
{
stemp[i]=csum%2;
csum=csum/2;
i++;
}
System.out.print("The checksum in binary is=");
for(int j=15;j>=0;j--)
{
System.out.print(stemp[j]);
}

}

}

Expected Output:

.......WELCOME TO CHECKSUM CALCULATION........
The checksum in decimal is=26900
The checksum in binary is=0110100100010100