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

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

Reference Type: Supported, Category: Other Functions, Integration Agreement: 3156

Description

This extrinsic function computes a Cyclic Redundancy Code (CRC) of the 8-bit character string, using X^16 + X^15 + X^2 + 1 as the polynomial. The optional parameter "seed" may supply an initial value, which allows for running CRC calculations on multiple strings. If the parameter "seed" is not specified, a default value of zero (0) is assumed. The value of "seed" is limited to 0 <= seed <= 2^16. The function value will be 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.

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.

 


VA (Internet) / VA(Intranet) / OI / PD / Site Map / Terms of Use / VA Privacy Policy / Accessibility

Reviewed/Updated: August 26, 2011

If you have questions, need more information, or are having accessibility problems with this website, please contact us by E-Mail: Webmasters, Phone: 510-768-6800, or FAX: 510-768-6850.