![]() ![]() |
Reference Type: Supported, Category: Other Functions, ICR#: 3156
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.
$$CRC16^XLFCRC(string[,seed])
string: |
(required) String upon which to compute the CRC16. |
seed: |
(optional) Seed value. Needed to compute the CRC16 over multiple strings. |
returns: |
Returns the Cyclic Redundancy Code (CRC) 16 value. |
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.
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.