Kernel 8.0 APIs Banner
Office of Information and Technology (OIT) Banner
[skip navigation]

$$CRC16^XLFCRC(): Cyclic Redundancy Code 16

Reference Type: Supported, Category: Other Functions, ICR#: 3156

Description

The $$CRC16^XLFCRC extrinsic function computes a Cyclic Redundancy Code (CRC) of the 8-bit character string, using the following as the polynomial:

    X^16 + X^15 + X^2 + 1

The optional seed input parameter can supply an initial value, which allows for running CRC calculations on multiple strings. If the seed input parameter is not specified, a default value of zero (0) is assumed. The seed value is limited to 0 <= seed <= 2^16. The function value is between 0 and 2^16.

Format

  $$CRC16^XLFCRC(string[,seed])

Input Parameters

string:

(required) String upon which to compute the CRC16.

seed:

(optional) Seed value. Needed to compute the CRC16 over multiple strings.

Output

returns:

Returns the Cyclic Redundancy Code (CRC) 16 value.

Examples

Example 1

SET CRC=$$CRC32^XLFCRC(string)

A checksum can also be calculated over multiple strings.

SET (I,C)=0
FOR SET I=$ORDER(X(I)) QUIT:'I DO 
. SET C=$$CRC16^XLFCRC(X(I),C)

Or:

SET I=0,C=4294967295
FOR SET I=$ORDER(X(I)) QUIT:'I DO 
. SET C=$$CRC16^XLFCRC(X(I),C)

As long as the save method is used all the time.

Example 2

CRC162 ;Test call CRC16^XLFCRC multiple times
S TEXT="Now is the time for all good children",TEXT2="to come to the aid of their country."
S CRC=0,CRC=$$CRC16^XLFCRC(TEXT,CRC)
If 23166=$$CRC16^XLFCRC(TEXT2,CRC) WRITE !,"CRC16 OK"
Q

NOTE: These have been approved for inclusion in a future ANSI M language standard as part of the library.