Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get CRC checksum of an NSData in Objective-C

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

Thanks in advance!

like image 461
Knodel Avatar asked Nov 06 '10 20:11

Knodel


2 Answers

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

like image 118
5lava Avatar answered Sep 29 '22 06:09

5lava


From iOS11 use this:

unsigned long result = crc32_z(0, data.bytes, data.length);
like image 1
AlexeyVMP Avatar answered Sep 28 '22 06:09

AlexeyVMP