Open-Source-Software-Entwicklung und Downloads

Browse Subversion Repository

Contents of /trunk/doc/en/html/macro/command/crc32.html

Parent Directory Parent Directory | Revision Log Revision Log


Revision 988 - (show annotations) (download) (as text)
Fri Sep 19 15:03:48 2008 UTC (15 years, 8 months ago) by maya
Original Path: doc/trunk/en/html/macro/command/crc32.html
File MIME type: text/html
File size: 1868 byte(s)
no message

1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2 "http://www.w3.org/TR/html4/strict.dtd">
3 <html>
4 <head>
5 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
6 <title>crc32</title>
7 <meta http-equiv="Content-Style-Type" content="text/css">
8 <link rel="stylesheet" href="../../style.css" type="text/css">
9 </head>
10
11 <body>
12
13
14 <h1>crc32</h1>
15
16 <p>
17 Calculates the CRC-32 of a string or a file.
18 </p>
19
20 <pre class="macro-syntax">
21 crc32 &lt;intvar&gt; &lt;string&gt;
22 crc32file &lt;intvar&gt; &lt;filename&gt;
23 </pre>
24
25 <h2>Remarks</h2>
26
27 <p>
28 This macro function calculates the CRC(Cyclic Redundancy Checking) of a string or a file. The polynomial expression(right rotation) is as follows:
29 <br><br>
30
31 100000100110000010001110110110111 (x<sup>32</sup>+x<sup>26</sup>+x<sup>23</sup>+x<sup>22</sup>+x<sup>16</sup>+x<sup>12</sup>+x<sup>11</sup>+x<sup>10</sup>+x<sup>8</sup>+x<sup>7</sup>+x<sup>5</sup>+x<sup>4</sup>+x<sup>2</sup>+x<sup>1</sup>+x<sup>0</sup>)
32 <br><br>
33
34 The calculated value stores the variable "intvar" as mathematical value.<br>
35 </p>
36
37 The CRC algorithm implementation is as follows:
38 <pre class="macro-example">
39 <code>
40 #define CRCPOLY2 0xEDB88320UL /* left-right reversal */
41
42 static unsigned long crc2(int n, unsigned char c[])
43 {
44 int i, j;
45 unsigned long r;
46
47 r = 0xFFFFFFFFUL;
48 for (i = 0; i < n; i++) {
49 r ^= c[i];
50 for (j = 0; j < CHAR_BIT; j++)
51 if (r & 1) r = (r >> 1) ^ CRCPOLY2;
52 else r >>= 1;
53 }
54 return r ^ 0xFFFFFFFFUL;
55 }
56 </code></pre>
57
58
59 <h2>Example</h2>
60
61 <pre class="macro-example">
62 <code>
63 str = 'this is a test string to be CRC32ed'
64 crc32 crc str
65
66 ; Display CRC32 result asHEX
67 sprintf '0x%08X' crc
68 messagebox inputstr 'CRC32 = '
69
70 crc32file crc 'foo.bin'
71 if result = -1 then
72 messagebox 'file open error' 'CRC32 = '
73 else
74 sprintf '0x%08X' crc
75 messagebox inputstr 'CRC32 = '
76 endif
77 </code></pre>
78
79 </body>
80 </html>

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26