Given a data buffer (byte sequence), this function performs the CRC16 calculation based on the specified polynomial and initial CRC value.
Syntax |
u16 crc16_be (string strData, i32 nCount [, u16 initVal=0xFFFF] [, u16 polin=0xA001]) |
||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
strData |
String or array, of which CRC16 is to be calculated. However, the CRC calculation is done on bytes, regardless of the type specified for the given variable |
||||||||||||||||||||||||||||||||
nCount |
This is the number of bytes of strData on which to perform the calculation |
||||||||||||||||||||||||||||||||
initVal |
Initial value of CRC. (optional, default 0xFFFF) |
||||||||||||||||||||||||||||||||
polin |
Value of the polynomial used in CRC calculation. (optional, default 0xA001) Main polynomials used by different CRCs:
Frequent cases:
|
||||||||||||||||||||||||||||||||
Result |
Returns the calculated CRC value |
||||||||||||||||||||||||||||||||
Validity |
Rule, Task |
||||||||||||||||||||||||||||||||
Note |
By repeatedly calling the function with initial value equal to the calculated CRC value, it is possible to perform incremental calculation of the CRC of a buffer of any length. NOTE: The previous functions crc16 and crc16_init are deprecated, but remain for compatibility. |
The calculation is done according to the Big Endian algorithm.
It differs from the crc16_le() algorithm because a shift of the CRC being processed is made to the left instead of the right and because the data byte is inserted at the top instead of the bottom of the word on which the calculation is performed.
Example of use:
|