Get CRC checksum of an NSData in Objective-C

Knodel picture Knodel · Nov 6, 2010 · Viewed 12.2k times · Source

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

Thanks in advance!

Answer

5lava picture 5lava · Jan 26, 2013

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