Get CRC checksum of an NSData in Objective-C

后端 未结 2 1652
难免孤独
难免孤独 2020-12-05 08:16

How can I count CRC (32 or 64) of an NSData object in Objective-C?

Thanks in advance!

相关标签:
2条回答
  • 2020-12-05 08:37

    From iOS11 use this:

    unsigned long result = crc32_z(0, data.bytes, data.length);
    
    0 讨论(0)
  • 2020-12-05 08:40

    Use crc32() function from zlib library:

    #import <zlib.h>
    
    NSData *data;
    
    // ...
    
    unsigned long result = crc32(0, data.bytes, data.length);
    NSLog(@"CRC32: %lu", result);
    

    Make sure to link libz library with your project:

    enter image description here

    0 讨论(0)
提交回复
热议问题