Appendix 5 check sum calculation method, Appendix 5, Check sum calculation method – Yokogawa Touch Screen GP20 User Manual

Page 109: 12 app

Advertising
background image

App-7

IM 04L51B01-17EN

Appendix

1

2

App

Appendix 5 Check Sum Calculation Method

The check sum of binary data is calculated using an algorithm like the one shown below.

int CalcSum(unsigned char *buf, int len)

{

int odd;

unsigned long

sum;

unsigned char

*p;

sum = 0;

odd = len & 1;

len >>= 1;

for (p = buf ; len ; len --, p += 2)

{

sum += (*p << 8) | *(p + 1);

}

if (odd) sum += (*p << 8);

sum = (sum & 0xffff) + ((sum >> 16) & 0xffff);

if (sum > 0xffff)

sum = sum - 0xffff;

return ((~sum) & 0xffff);

}

Advertising
This manual is related to the following products: