source: WorldVistAEHR/trunk/r/KERNEL-XU-A4A7-USC-XG-XLF-XNOA-XPD-XQ-XVIR-ZI-ZOSF-ZOSV-ZT-ZU-%Z-XIP--XQAB--XUC--XUR--ZIN--ZTED/XLFCRC.m@ 1524

Last change on this file since 1524 was 613, checked in by George Lilly, 15 years ago

initial load of WorldVistAEHR

File size: 1.2 KB
Line 
1XLFCRC ;ISF/RWF - Library Functions to do CRC ;08/04/2000 09:42
2 ;;8.0;KERNEL;**166**;Jul 10, 1995
3 ; The code below was approved in document X11/1998-32
4 ;From the book "M[UMPS] by example" by Ed de Mole.
5 ;
6CRC32(string,seed) ;
7 ; Polynomial X**32 + X**26 + X**23 + X**22 +
8 ; + X**16 + X**12 + X**11 + X**10 +
9 ; + X**8 + X**7 + X**5 + X**4 +
10 ; + X**2 + X + 1
11 N I,J,R
12 I '$D(seed) S R=4294967295
13 E I seed'<0,seed'>4294967295 S R=4294967295-seed
14 E S $ECODE=",M28,"
15 F I=1:1:$L(string) D
16 . S R=$$XOR($A(string,I),R,8)
17 . F J=0:1:7 D
18 . . I R#2 S R=$$XOR(R\2,3988292384,32)
19 . . E S R=R\2
20 . . Q
21 . Q
22 Q 4294967295-R
23 ;
24XOR(a,b,w) N I,M,R
25 S R=b,M=1
26 F I=1:1:w D
27 . S:a\M#2 R=R+$S(R\M#2:-M,1:M)
28 . S M=M+M
29 . Q
30 Q R
31 ; ===
32 ;
33 ; The code below was approved in document X11/1998-32
34 ;
35CRC16(string,seed) ;
36 ; Polynomial x**16 + x**15 + x**2 + x**0
37 N I,J,R
38 I '$D(seed) S R=0
39 E I seed'<0,seed'>65535 S R=seed\1
40 E S $ECODE=",M28,"
41 F I=1:1:$L(string) D
42 . S R=$$XOR($A(string,I),R,8)
43 . F J=0:1:7 D
44 . . I R#2 S R=$$XOR(R\2,40961,16)
45 . . E S R=R\2
46 . . Q
47 . Q
48 Q R
49 ;
50ZXOR(a,b,w) NEW I,M,R
51 SET R=b,M=1
52 FOR I=1:1:w DO
53 . SET:a\M#2 R=R+$SELECT(R\M#2:-M,1:M)
54 . SET M=M+M
55 . QUIT
56 QUIT R
57 ;
58
Note: See TracBrowser for help on using the repository browser.