CHECKSUM USING C

#include<stdio.h>
static int c;
int Add(int a,int b)
{
if(a==0&&b==0&&c==1)
{
    c=0;
    return 1;
}
if(a==0&&b==1&&c==1)
{
c=1;
return 0;
}
if(a==0&&b==0&&c==0)
{
c=0;
return 0;
}
if(a==1&&b==1&&c==1)
{
c=1;
return 1;
}
if(a==1&&b==0&&c==0)
  {
  c=0;
  return 1;
  }
if(a==1&&b==0&&c==1)
{
c=1;
return 0;
}
if(a==0&&b==1&&c==0)
{
 c=0; return 1;
}
if(a==1&&b==1&&c==0)
{
  c=1;return 0;
}
}

int main()
{
int d[32]={1,1,1,0,0,1,1,1,1,1,0,1,1,1,0,1,0,0,1,1,1,0,0,1,1,0,1,0,1,0,0,1},n=32,t;
int d1=8,i,j;
int carry[8]={0,0,0,0,0,0,0,0};
int checksum[8]={0};
for(i=0;i<n;i=i+d1)
{

  for(j=7;j>=0;j--)
{
checksum[j]=Add(d[i+j],checksum[j]);
}
while(c!=0)
{
    for(j=7;j>=0;j--)
{
checksum[j]=Add(carry[j],checksum[j]);
}
}

}
printf("\nchecksum\n");
 for(j=0;j<=7;j++)
{
printf("\t %d",checksum[j]);
checksum[j]=0;
}
}

Comments

Popular posts from this blog

BYTE STUFFING PROGRAM USING C

Rotate a matrix 270 degree AntiClockWise

Finding the length of connected cells of 1's (regions) in an matrix of 1's and 0's