我在xcode中找不到CRC32 algoryghm的任何实现。任何人都可以帮我计算一下吗?
答案 0 :(得分:15)
libz
具有crc32()
功能。要将其与NSData一起使用,请尝试以下简单类别:
你的标题:
@interface NSData (CRC32)
- (uint32_t)CRC32Value;
@end
您的实施:
#include "your header"
#include <zlib.h>
@implementation NSData (CRC32)
- (uint32_t)CRC32Value {
uLong crc = crc32(0L, Z_NULL, 0);
crc = crc32(crc, [self bytes], [self length]);
return crc;
}
@end