Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculate a Checksum

Status
Not open for further replies.

youssef

Programmer
Joined
Mar 13, 2001
Messages
96
Location
BE
Hi,

I would like to create a function to calculate a checksum for a arraydata.

But I don't understand what I want for this checksum :

" lower 8 bits of the sum from data1 to data10 equals to zero".

My english is not perfect but I understand the sum of the data1 to data10 but equals to zero, I don't understand.

Best regards
 
Hi, there!
What does "lower 8 bits" mean? I am not quite clear on what it is exactly that you need to do, but could it be that you are asked to initialise the first 8 elements to zero first?
If so, then in Borland C++Builder that would look something like this:
int i = 0; //initialise index
int DataArray[10]; //declare your array (if
//your data consists of integers
while (i < 8)
{
DataArray = 0;
i = i + 1;
}
I hope I got the question right? And I'm sorry if that's not what is expected - I'm only a beginner myself!
CluelessC.
 
I did something like this for a group of byte elements. See if u can convert this to yr array

UNSIGNED32 seed = 0x746d7361;
UNSIGNED32 i, icVal0 = seed, icVal1 = 0;
BYTE* pg = *ptrToBeginningOfArray;
for (i = 0; i < numBytes; i++, pg++)
{
icVal0 += *pg;
icVal1 += icVal0;
}


Sriks
 
Last time i worked with checksums was about a year ago but the way mine worked was the current value and the checksum added together would equal zero. I did something along the lines of this:

return (current_value + (~checksum+1)) == 0;

I dont remember if this was exactly what i did but i do know i used two's compliment to determine if the checksum was correct.


Matt

 
Thanks for your answer

It is work
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top