如何使用boost::crc?
我想使用 boost::crc ,以便它的工作方式与 PHP 的 crc32()< /a> 函数。我尝试阅读 可怕的文档,后来我遇到了很多头痛没有取得任何进展。
显然我必须做一些类似的事情:
int GetCrc32(const string& my_string) {
return crc_32 = boost::crc<bits, TruncPoly, InitRem, FinalXor,
ReflectIn, ReflectRem>(my_string.c_str(), my_string.length());
}
bits
应该是32..其他的东西是什么是个谜。有一点帮助吗? ;)
I want to use boost::crc so that it works exactly like PHP's crc32() function. I tried reading the horrible documentation and many headaches later I haven't made any progress.
Apparently I have to do something like:
int GetCrc32(const string& my_string) {
return crc_32 = boost::crc<bits, TruncPoly, InitRem, FinalXor,
ReflectIn, ReflectRem>(my_string.c_str(), my_string.length());
}
bits
should be 32.. What the other things are is a mystery. A little help? ;)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
Dan Story 和 ergosys 提供了很好的答案(显然我找错了地方,这就是头痛的原因),但当我这样做时,我想为未来的谷歌用户提供一个复制和粘贴解决方案:
Dan Story and ergosys provided good answers (apparently I was looking in the wrong place, that's why the headaches) but while I'm at it I wanted to provide a copy&paste solution for the function in my question for future googlers:
您可能想使用
crc_32_type
而不是使用 crc 模板。该模板是通用的,旨在适应使用广泛变化的参数的各种 CRC 设计,但它们提供四种内置的预配置 CRC 类型供常用,涵盖 CRC16、CCITT、XMODEM 和 CRC32。You probably want to use the
crc_32_type
instead of using the crc template. The template is general and meant to accommodate a wide range of CRC designs using widely varying parameters, but they ship four built-in pre-configured CRC types for common usage, covering CRC16, CCITT, XMODEM and CRC32.该库包含预定义的 CRC 引擎。我认为你想要的是crc_32_type。请参阅此示例: http://www.boost.org/doc /libs/1_37_0/libs/crc/crc_example.cpp
The library includes predefined CRC engines. I think the one you want is crc_32_type. See this example: http://www.boost.org/doc/libs/1_37_0/libs/crc/crc_example.cpp
您是否尝试过使用预定义的
crc_32_type
?Have you tried using the predefined
crc_32_type
?在此页面上,找到您想要的特定 32 位 CRC,读出所有其他参数:
http://regregex.bbcmicro.net/crc-catalogue.htm
On this page, find the particular 32-bit CRC you want, read off all the other parameters:
http://regregex.bbcmicro.net/crc-catalogue.htm