Please enable JavaScript to view this site.

This function, given a data buffer (sequence of bytes), performs the CRC16 calculation based on the specified polynomial and initial CRC value.

Syntax

u16 crc16_le (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:

Polynomial

Polin value

Normal original

0x8005

Normal reversed

0xA001

Koopman original

0xC002

Normal reciprocal

0x4003

Reversed reciprocal

0xC002

Koopman reciprocal

0xA001

Frequent cases:

Most used CRCs

Representation

NORMAL

REVERSE

RECIPROCAL

Used by

CRC-16-CCITT

x16 + x12 + x5 + 1

0x1021

0x8408

0x0811

ModemX25, Bluetooth, PPP

CRC-16-IBM

x16 + x15 + x2 + 1

0x8005

0xa001

0x4003

USB, MODBUS, altri

Result

Returns the calculated CRC value

Validity

Rule, Task

Note

By repeatedly calling the function with initial value equal to the calculated CRC value, one can perform incremental calculation of the CRC of a buffer of any length.

NOTE: The previous crc16_ero function (Little Endian with unmodifiable initial polynomial 0xA001) is deprecated, but remains for compatibility.

The calculation is done according to the Little Endian algorithm.

 

  

Keyboard Navigation

F7 for caret browsing
Hold ALT and press letter

This Info: ALT+q
Page Header: ALT+h
Topic Header: ALT+t
Topic Body: ALT+b
Contents: ALT+c
Search: ALT+s
Exit Menu/Up: ESC