Giter VIP home page Giter VIP logo

Comments (3)

jiladahe1997 avatar jiladahe1997 commented on August 30, 2024

应该是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.

5ooo avatar 5ooo commented on August 30, 2024

应该是因为32位机器和64位机器的long所占字节不一样导致的。
假设(crc32val ^ 0xFFFFFFFF)的值是4048690643,如果long占4个字节,labs返回值是246276653(也就是把4048690643当作-246276653了),如果long占8个字节,那么labs的返回值还是4048690643,这就导致不同机器计算出来的crc不一样,是补码关系了
解决:我这边是去掉最后的labs就可以了,计算都是用uint32_t的值,最后不用调用labs

from crc.

mygityf avatar mygityf commented on August 30, 2024

你的方法是对的。

from crc.

Related Issues (3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.