简体   繁体   中英

Python - Why is result of CRC32(np.int64(1)) different to CRC32(np.int32(1))?

CRC32 comparisons in Python:

>>> zlib.crc32(np.int64(1)) == zlib.crc32(np.int32(1))
False

>>> np.int64(1) == np.int32(1)
True

>>> zlib.crc32(np.int64(1))
2844319735

>>> zlib.crc32(np.int32(1))
2583214201

The polynomial expression of 1, regardless of its int64 or int32 data type, should be the same and yet their CRC32 results are different. I've tried many other numbers than 1 and the CRC32 of the int64 and int32 results still won't match.

Any help in clearing up this incredibly confusing issue would be very much appreciated.

cbc32 works on bytes.

int32 is 4 bytes, 1 is 01 00 00 00

int64 is 8 bytes, 1 is 01 00 00 00 00 00 00 00

>>> zlib.crc32(np.int64(1)) == zlib.crc32(b''.join([np.int32(1), np.int32(0)]))
True

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM