absfast123
New Member
I have got checksum method from a book. that is
1) add all bytes dropping carries (example add all bytes into a byte type variable)
2) takes invert of all bytes sum add 1 (it will be 2's compliment)
3) this will be the checksum
verification:
add all bytes and checksum the answer will the 0
if not it means wrong checksum
problem is that in electronics world many times if there is a problem in PIN that will be low(o). if that is the data pin then all data will be the zero, hence checksum will also be the zero and upon verification it will say correct data arrived. I need its solution.
code of upper algo is as
.AB Sami
1) add all bytes dropping carries (example add all bytes into a byte type variable)
2) takes invert of all bytes sum add 1 (it will be 2's compliment)
3) this will be the checksum
verification:
add all bytes and checksum the answer will the 0
if not it means wrong checksum
problem is that in electronics world many times if there is a problem in PIN that will be low(o). if that is the data pin then all data will be the zero, hence checksum will also be the zero and upon verification it will say correct data arrived. I need its solution.
code of upper algo is as
Code:
unsigned char calc_checksum(unsigned char *Array,unsigned char len)
{
unsigned char i;
unsigned char sum=0;
for(i=0;i<len;i++)
sum+=*Array++;
return ~sum+1;
}
unsigned char verify_checksum(unsigned char *Array,unsigned char len)
{
unsigned char sum=0;
while(len--)
{
sum+=*Array++;
}
if(!sum)
return 1;
else
return 0;
}