Comments (3)
应该是labs()求了绝对值的问题,0x0294be25 和 0xfd6b41db刚好是补码的关系。
crc32.c 第77行。
uint32_t crc32(const char* s, int len)
{
int i;
uint32_t crc32val = 0;
crc32val ^= 0xFFFFFFFF;
for (i = 0; i < len; i++) {
crc32val = crc32_tab[(crc32val ^ s[i]) & 0xFF] ^ ((crc32val >> 8) & 0x00FFFFFF);
}
return labs(crc32val ^ 0xFFFFFFFF);
}
from crc.
应该是因为32位机器和64位机器的long所占字节不一样导致的。
假设(crc32val ^ 0xFFFFFFFF)的值是4048690643,如果long占4个字节,labs返回值是246276653(也就是把4048690643当作-246276653了),如果long占8个字节,那么labs的返回值还是4048690643,这就导致不同机器计算出来的crc不一样,是补码关系了
解决:我这边是去掉最后的labs就可以了,计算都是用uint32_t的值,最后不用调用labs
from crc.
你的方法是对的。
from crc.
Related Issues (3)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from crc.