Posted By

zava on 08/05/10


Tagged

checksum


Versions (?)

simple Longitudinal redundancy check


 / Published in: C
 

  1. // Longitudinal redundancy check
  2. char checksum(char* s)
  3. {
  4. char sum = 0;
  5. while (*s != 0)
  6. {
  7. sum ^= *s;
  8. s++;
  9. }
  10. return sum;
  11. }
  12.  
  13. char checksumData(char* data, const int size)
  14. {
  15. char sum = 0;
  16. int l = size;
  17. while (l != 0)
  18. {
  19. sum ^= *data;
  20. data++;
  21. l--;
  22. }
  23. return sum;
  24. }
  25.  
  26. int main()
  27. {
  28. char s[] = "Hello world!\n";
  29. char sum = checksum(s);
  30. printf("%dn", sum);
  31. sum = checksumData(s, 13);
  32. printf("%dn", sum);
  33. return 0;
  34. }

Report this snippet  

You need to login to post a comment.