Please enable JavaScript to view this site.

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:

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, 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.

 

  

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