Open-Source-Software-Entwicklung und Downloads

Browse Subversion Repository

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1037 - (hide annotations) (download) (as text)
Wed Oct 22 15:20:31 2008 UTC (15 years, 7 months ago) by yutakapon
Original Path: doc/trunk/en/html/macro/command/crc32.html
File MIME type: text/html
File size: 1918 byte(s)
*** empty log message ***

1 yutakapon 982 <!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 yutakapon 985 Calculates the CRC-32 of a string or a file.
18 yutakapon 982 </p>
19    
20     <pre class="macro-syntax">
21 maya 988 crc32 &lt;intvar&gt; &lt;string&gt;
22     crc32file &lt;intvar&gt; &lt;filename&gt;
23 yutakapon 982 </pre>
24    
25     <h2>Remarks</h2>
26    
27     <p>
28 yutakapon 985 This macro function calculates the CRC(Cyclic Redundancy Checking) of a string or a file. The polynomial expression(right rotation) is as follows:
29 yutakapon 982 <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 maya 988 The calculated value stores the variable "intvar" as mathematical value.<br>
35 yutakapon 982 </p>
36    
37 yutakapon 1037 The CRC algorithm implementation by C language is as follows:
38     This algorithm is often used as the Ethernet FCS(Frame Check Sequence).
39 yutakapon 1029 <pre>
40 yutakapon 986 <code>
41     #define CRCPOLY2 0xEDB88320UL /* left-right reversal */
42    
43     static unsigned long crc2(int n, unsigned char c[])
44     {
45     int i, j;
46     unsigned long r;
47    
48     r = 0xFFFFFFFFUL;
49     for (i = 0; i < n; i++) {
50     r ^= c[i];
51     for (j = 0; j < CHAR_BIT; j++)
52     if (r & 1) r = (r >> 1) ^ CRCPOLY2;
53     else r >>= 1;
54     }
55     return r ^ 0xFFFFFFFFUL;
56     }
57     </code></pre>
58    
59    
60 yutakapon 982 <h2>Example</h2>
61    
62     <pre class="macro-example">
63     str = 'this is a test string to be CRC32ed'
64 maya 988 crc32 crc str
65 yutakapon 982
66     ; Display CRC32 result asHEX
67 maya 988 sprintf '0x%08X' crc
68 yutakapon 982 messagebox inputstr 'CRC32 = '
69 yutakapon 985
70 maya 988 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 maya 1034 </pre>
78 yutakapon 982
79     </body>
80     </html>

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