What Is a Checksum Algorithm?
Checksum, in the field of data processing and data communication, is used to check the sum of a set of data items at the destination. It is usually in the form of a hexadecimal number system. If the value of the checksum exceeds hexadecimal FF, which is 255. The complement is required as the checksum. It is usually used to ensure the integrity and accuracy of data in communication, especially in long-distance communication.
- These ones
- Sender generates checksum
- 1. Divide the sent data for checksum operation into several 16-bit bit strings, and each bit string is regarded as one
- Such as:
- Hex string: 0102030405060708
- The checksum is: 24 (hex)
- IP header checksum calculation
- The IP header checksum field is a checksum code calculated based on the IP header. It does not calculate data after the header. ICMP, IGMP, UDP, and TCP all include in their respective headers both a header and
#include <stdio.h> int main () { int a [8] = {0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08}; int i, sum = 0; for (i = 0; i <8; i ++) sum + = a [i]; // Add each number if (sum> 0xff) { sum = ~ sum; sum + = 1; } sum = sum & 0xff; printf ("0x% x \ n", sum); }