crc16 マクロコマンドの説明を修正
MFT to: 4-stable
ticket #40615
ヘルプ
ソースコード
@@ -14,7 +14,7 @@ | ||
14 | 14 | <h1>crc16, crc16file</h1> |
15 | 15 | |
16 | 16 | <p> |
17 | -Calculates the CRC-16-IBM of a string or a file. | |
17 | +Calculates the CRC-16-CCITT of a string or a file. | |
18 | 18 | </p> |
19 | 19 | |
20 | 20 | <pre class="macro-syntax"> |
@@ -28,7 +28,7 @@ | ||
28 | 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 | 29 | <br><br> |
30 | 30 | |
31 | -0xA001 (x<sup>16</sup>+x<sup>15</sup>+x<sup>2</sup>+x<sup>0</sup>) | |
31 | +10001000000100001 (x<sup>16</sup>+x<sup>12</sup>+x<sup>5</sup>+x<sup>0</sup>) | |
32 | 32 | <br><br> |
33 | 33 | |
34 | 34 | The calculated value stores the variable "intvar" as mathematical value.<br> |
@@ -40,8 +40,8 @@ | ||
40 | 40 | <code> |
41 | 41 | static unsigned int crc16(int n, unsigned char c[]) |
42 | 42 | { |
43 | +#define CRC16POLY1 0x1021U | |
43 | 44 | #define CRC16POLY2 0x8408U /* left-right reversal */ |
44 | - | |
45 | 45 | int i, j; |
46 | 46 | unsigned long r; |
47 | 47 |
@@ -60,19 +60,19 @@ | ||
60 | 60 | <h2>Example</h2> |
61 | 61 | |
62 | 62 | <pre class="macro-example"> |
63 | -str = 'this is a test string to be crc16ed' | |
63 | +str = 'this is a test string to be CRC16ed' | |
64 | 64 | crc16 crc str |
65 | 65 | |
66 | -; Display crc16 result asHEX | |
66 | +; Display CRC16 result asHEX | |
67 | 67 | sprintf '0x%08X' crc |
68 | -messagebox inputstr 'crc16 = ' | |
68 | +messagebox inputstr 'CRC16 = ' | |
69 | 69 | |
70 | 70 | crc16file crc 'foo.bin' |
71 | 71 | if result = -1 then |
72 | - messagebox 'file open error' 'crc16 = ' | |
72 | + messagebox 'file open error' 'CRC16 = ' | |
73 | 73 | else |
74 | 74 | sprintf '0x%08X' crc |
75 | - messagebox inputstr 'crc16 = ' | |
75 | + messagebox inputstr 'CRC16 = ' | |
76 | 76 | endif |
77 | 77 | </pre> |
78 | 78 |
@@ -39,10 +39,10 @@ | ||
39 | 39 | This algorithm is often used as the Ethernet FCS(Frame Check Sequence). |
40 | 40 | <pre> |
41 | 41 | <code> |
42 | -#define CRCPOLY2 0xEDB88320UL /* left-right reversal */ | |
43 | - | |
44 | -static unsigned long crc2(int n, unsigned char c[]) | |
42 | +static unsigned long crc32(int n, unsigned char c[]) | |
45 | 43 | { |
44 | +#define CRC32POLY1 0x04C11DB7UL | |
45 | +#define CRC32POLY2 0xEDB88320UL /* left-right reversal */ | |
46 | 46 | int i, j; |
47 | 47 | unsigned long r; |
48 | 48 |
@@ -50,7 +50,7 @@ | ||
50 | 50 | for (i = 0; i < n; i++) { |
51 | 51 | r ^= c[i]; |
52 | 52 | for (j = 0; j < CHAR_BIT; j++) |
53 | - if (r & 1) r = (r >> 1) ^ CRCPOLY2; | |
53 | + if (r & 1) r = (r >> 1) ^ CRC32POLY2; | |
54 | 54 | else r >>= 1; |
55 | 55 | } |
56 | 56 | return r ^ 0xFFFFFFFFUL; |
@@ -14,7 +14,7 @@ | ||
14 | 14 | <h1>crc16, crc16file</h1> |
15 | 15 | |
16 | 16 | <p> |
17 | -CRC-16-IBMを計算する。 | |
17 | +CRC-16-CCITTを計算する。 | |
18 | 18 | </p> |
19 | 19 | |
20 | 20 | <pre class="macro-syntax"> |
@@ -28,7 +28,7 @@ | ||
28 | 28 | 引数の文字列およびファイルからCRC(Cyclic Redundancy Checking)を計算する。多項式(右回り)は以下のとおり。 |
29 | 29 | <br><br> |
30 | 30 | |
31 | -0xA001 (x<sup>16</sup>+x<sup>15</sup>+x<sup>2</sup>+x<sup>0</sup>) | |
31 | +10001000000100001 (x<sup>16</sup>+x<sup>12</sup>+x<sup>5</sup>+x<sup>0</sup>) | |
32 | 32 | <br><br> |
33 | 33 | |
34 | 34 | 計算結果は intvar 変数に数値として格納される。<br> |
@@ -40,8 +40,8 @@ | ||
40 | 40 | <code> |
41 | 41 | static unsigned int crc16(int n, unsigned char c[]) |
42 | 42 | { |
43 | +#define CRC16POLY1 0x1021U | |
43 | 44 | #define CRC16POLY2 0x8408U /* 左右逆転 */ |
44 | - | |
45 | 45 | int i, j; |
46 | 46 | unsigned long r; |
47 | 47 |
@@ -38,10 +38,10 @@ | ||
38 | 38 | CRCアルゴリズムの実装(C言語)を以下に示す。このアルゴリズムは、EthernetのFCS(Frame Check Sequence)に適用されている。 |
39 | 39 | <pre> |
40 | 40 | <code> |
41 | -#define CRCPOLY2 0xEDB88320UL /* 左右逆転 */ | |
42 | - | |
43 | -static unsigned long crc2(int n, unsigned char c[]) | |
41 | +static unsigned long crc32(int n, unsigned char c[]) | |
44 | 42 | { |
43 | +#define CRC32POLY1 0x04C11DB7UL | |
44 | +#define CRC32POLY2 0xEDB88320UL /* 左右逆転 */ | |
45 | 45 | int i, j; |
46 | 46 | unsigned long r; |
47 | 47 |
@@ -49,7 +49,7 @@ | ||
49 | 49 | for (i = 0; i < n; i++) { |
50 | 50 | r ^= c[i]; |
51 | 51 | for (j = 0; j < CHAR_BIT; j++) |
52 | - if (r & 1) r = (r >> 1) ^ CRCPOLY2; | |
52 | + if (r & 1) r = (r >> 1) ^ CRC32POLY2; | |
53 | 53 | else r >>= 1; |
54 | 54 | } |
55 | 55 | return r ^ 0xFFFFFFFFUL; |
@@ -635,7 +635,7 @@ | ||
635 | 635 | static unsigned long crc32(int n, unsigned char c[]) |
636 | 636 | { |
637 | 637 | #define CRC32POLY1 0x04C11DB7UL |
638 | - /* x^{32}+x^{26}+x^{23}+x^{22}+x^{16}+x^{12}+x^{11]+ | |
638 | + /* x^{32}+x^{26}+x^{23}+x^{22}+x^{16}+x^{12}+x^{11}+ | |
639 | 639 | x^{10}+x^8+x^7+x^5+x^4+x^2+x^1+1 */ |
640 | 640 | #define CRC32POLY2 0xEDB88320UL /* 左右逆転 */ |
641 | 641 | int i, j; |