{"id":208226,"date":"2025-07-08T08:26:34","date_gmt":"2025-07-08T00:26:34","guid":{"rendered":"https:\/\/server.hk\/cnblog\/208226\/"},"modified":"2025-07-08T08:26:34","modified_gmt":"2025-07-08T00:26:34","slug":"%e5%b0%86-crc32-%e6%80%bb%e5%92%8c%e4%bb%8e-lsb-%e4%bc%98%e5%85%88%e7%ae%97%e6%b3%95%e8%bd%ac%e6%8d%a2%e4%b8%ba-msb-%e4%bc%98%e5%85%88%e7%ae%97%e6%b3%95%e7%9a%84%e6%80%bb%e5%92%8c","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/208226\/","title":{"rendered":"\u5c06 CRC32 \u603b\u548c\u4ece LSB \u4f18\u5148\u7b97\u6cd5\u8f6c\u6362\u4e3a MSB \u4f18\u5148\u7b97\u6cd5\u7684\u603b\u548c"},"content":{"rendered":"<p><b><\/b> <\/p>\n<p>\u5f53\u524d\u4f4d\u7f6e\uff1a <span>&gt;<\/span> <span>&gt;<\/span> <span>&gt;<\/span> <span>&gt;<\/span> <span>\u5c06 CRC32 \u603b\u548c\u4ece LSB \u4f18\u5148\u7b97\u6cd5\u8f6c\u6362\u4e3a MSB \u4f18\u5148\u7b97\u6cd5\u7684\u603b\u548c<\/span><\/p>\n<p><span>\u6765\u6e90\uff1astackoverflow<\/span><br \/>\n<span>2024-04-30 15:00:42<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u4e00\u5206\u8015\u8018\uff0c\u4e00\u5206\u6536\u83b7\uff01\u65e2\u7136\u90fd\u6253\u5f00\u8fd9\u7bc7<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u5c06 CRC32 \u603b\u548c\u4ece LSB \u4f18\u5148\u7b97\u6cd5\u8f6c\u6362\u4e3a MSB \u4f18\u5148\u7b97\u6cd5\u7684\u603b\u548c\u300b<\/span>\uff0c\u5c31\u575a\u6301\u770b\u4e0b\u53bb\uff0c\u5b66\u4e0b\u53bb\u5427\uff01\u672c\u6587\u4e3b\u8981\u4f1a\u7ed9\u5927\u5bb6\u8bb2\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u5927\u5bb6\u5bf9\u672c\u6587\u6709\u597d\u7684\u5efa\u8bae\u6216\u8005\u770b\u5230\u6709\u4e0d\u8db3\u4e4b\u5904\uff0c\u975e\u5e38\u6b22\u8fce\u5927\u5bb6\u79ef\u6781\u63d0\u51fa\uff01\u5728\u540e\u7eed\u6587\u7ae0\u6211\u4f1a\u7ee7\u7eed\u66f4\u65b0<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">Golang<\/span>\u76f8\u5173\u7684\u5185\u5bb9\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u90fd\u6709\u6240\u5e2e\u52a9\uff01<\/p>\n<p> \u95ee\u9898\u5185\u5bb9<br \/>\n <\/p>\n<p>crc32 \u548c\u53ef\u4ee5\u8868\u793a\u4e3a\u6700\u4f4e\u6709\u6548\u4f4d\u5728\u524d\u6216\u6700\u9ad8\u6709\u6548\u4f4d\u5728\u524d\u3002\u4f8b\u5982\uff0cieee crc32 \u591a\u9879\u5f0f\u53ef\u4ee5\u8868\u793a\u4e3a <code>0xedb88320<\/code> \u6216 <code>0x4c11db7<\/code>\uff0c\u5e76\u5bf9 crc32 \u7b97\u6cd5\u8fdb\u884c\u76f8\u5173\u66f4\u6539\uff0c\u5982\u4e0b\u6240\u793a\uff08go \u4ee3\u7801\uff09\u3002<\/p>\n<p>lsb\u4f18\u5148\u7b97\u6cd5\uff08\u53cd\u5411\u8868\u793a\uff09\uff1a<\/p>\n<pre>func crc32update(crc uint32, tab *table, p []byte) uint32 {\n    crc = ^crc\n    for _, v := range p {\n        crc = tab[byte(crc)^v] ^ (crc &gt;&gt; 8)\n    }\n    return ^crc\n}<\/pre>\n<p>msb\u4f18\u5148\u7b97\u6cd5\uff08\u6b63\u5e38\u8868\u793a\uff09\uff1a<\/p>\n<pre>func crc32Update(crc uint32, tab *table, p []byte) uint32 {\n    crc = ^crc\n    for _, v := range p {\n        crc = tab[byte(crc&gt;&gt;24)^v] ^ (crc &lt;&lt; 8)\n    }\n    return ^crc\n}<\/pre>\n<p>\uff08\u8fd9\u4e9b\u4e0e crc32 \u8868\u6784\u9020\u4e2d\u7684\u76f8\u5173\u4f4d\u53cd\u8f6c\u66f4\u6539\u76f8\u5173\uff0c\u6211\u5728\u6b64\u672a\u5305\u542b\u8fd9\u4e9b\u66f4\u6539\uff0c\u4f46\u8bf7\u53c2\u9605\u8fd9\u4e24\u4e2a lsb \u548c msb \u7684\u6f14\u793a\u5b9e\u73b0\uff0c\u5305\u62ec\u5bf9 go std \u5e93\u5b9e\u73b0\u7684\u8c03\u7528\uff09\u3002<\/p>\n<p>\u6b63\u5982\u8fd9\u7bc7\u7ef4\u57fa\u767e\u79d1\u6587\u7ae0\u4e2d\u6240\u8ff0\uff0c\u53ef\u4ee5\u5c06 lsb \u7b97\u6cd5\u603b\u548c\u8f6c\u6362\u4e3a msb \u603b\u548c\u3002\u4f46\u662f\uff0c\u6211\u4e0d\u6e05\u695a\u8fd9\u5c06\u5982\u4f55\u5b9e\u65bd\u3002\u636e\u6211\u4e86\u89e3\uff0c\u94fe\u63a5\u7684\u6587\u7ae0\u8bf4\u6709\u4e00\u79cd\u65b9\u6cd5\u53ef\u4ee5\u6839\u636e $g(x) = x^ng(x^-1)$ \u5728\u4e24\u4e2a\u603b\u548c\u4e4b\u95f4\u8fdb\u884c\u76f8\u4e92\u8f6c\u6362\uff0c\u4f46\u6211\u4e0d\u660e\u767d\u5982\u4f55\u6211\u4f1a\u7ee7\u7eed\u5229\u7528\u8fd9\u79cd\u5173\u7cfb\u3002<\/p>\n<p>\u4efb\u4f55\u4eba\u90fd\u53ef\u4ee5\u5411\u6211\u6307\u51fa\u6bd4 wp \u6587\u7ae0\u66f4\u597d\u5730\u89e3\u91ca\u8fd9\u4e00\u70b9\u7684\u6587\u6863\uff0c\u4ee5\u4fbf\u6211\u53ef\u4ee5\u5bf9\u5176\u8fdb\u884c\u7f16\u7801\u5417\uff1f<\/p>\n<p>\u8fd9\u4e2a\u95ee\u9898\u7684\u539f\u56e0\u662f go \u4e2d\u7684\u6807\u51c6\u5e93\u63d0\u4f9b\u4e86\u5feb\u901f\u7684 lsb \u4f18\u5148\u5b9e\u73b0\uff0c\u4f46\u6211\u5fc5\u987b\u5904\u7406\u4f7f\u7528 msb \u4f18\u5148\u7b97\u6cd5\u6c42\u548c\u7684\u8f93\u5165\uff08mpeg-ts \u6570\u636e\u5305\u89c6\u9891\u6d41\uff09\u3002<\/p>\n<p> <\/p>\n<h2>\u89e3\u51b3\u65b9\u6848<\/h2>\n<p> <\/p>\n<p>\u60a8\u5b9e\u9645\u4e0a\u65e0\u6cd5\u5c06 CRC \u8f6c\u6362\u4e3a\u5012\u6570\u7248\u672c\uff0c\u4f46\u8fd9\u4e0d\u662f\u60a8\u9700\u8981\u505a\u7684\u3002\u60a8\u5f53\u7136<em>\u53ef\u4ee5<\/em>\u4f7f\u7528\u60a8\u5fc5\u987b\u7684\u6807\u51c6\u5e93\u51fd\u6570\u6765\u5b9e\u73b0\u60a8\u60f3\u8981\u7684 CRC\u3002<\/p>\n<p>\u4e24\u4e2a\u66f4\u65b0\u51fd\u6570\u6267\u884c\u76f8\u540c\u7684\u64cd\u4f5c\uff0c\u4f46\u5b83\u4eec\u5728 CRC \u591a\u9879\u5f0f\u672c\u8eab\u4e2d\u4f7f\u7528\u4e0d\u540c\u7684\u5b57\u8282\u987a\u5e8f\u3002<\/p>\n<p>\u8981\u4f7f MSB \u8868\u9002\u7528\u4e8e LSB \u66f4\u65b0\u529f\u80fd\uff0c\u53ea\u9700\u5bf9\u6bcf\u4e2a\u6761\u76ee\u8fdb\u884c\u5b57\u8282\u53cd\u8f6c\u5373\u53ef\u3002\u5b8c\u6210\u540e\uff0c\u5bf9\u7ed3\u679c\u8fdb\u884c\u5b57\u8282\u53cd\u8f6c\u3002<\/p>\n<p>\u6211\u5df2\u7ecf\u5728\u60a8\u7684\u5b9e\u73b0\u4e2d\u5c55\u793a\u4e86\u8fd9\u4e00\u70b9\uff1a<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u672c\u6587\u7684\u5168\u90e8\u5185\u5bb9\u4e86\uff0c\u662f\u5426\u6709\u987a\u5229\u5e2e\u52a9\u4f60\u89e3\u51b3\u95ee\u9898\uff1f\u82e5\u662f\u80fd\u7ed9\u4f60\u5e26\u6765\u5b66\u4e60\u4e0a\u7684\u5e2e\u52a9\uff0c\u8bf7\u5927\u5bb6\u591a\u591a\u652f\u6301\uff01\u66f4\u591a\u5173\u4e8eGolang\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u4e5f\u53ef\u5173\u6ce8\u516c\u4f17\u53f7\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f53\u524d\u4f4d\u7f6e\uff1a &gt; &gt; &#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-208226","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/208226","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=208226"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/208226\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=208226"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=208226"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=208226"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}