Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check CRC32 of NSData? [duplicate]

Tags:

iphone

crc32

Possible Duplicate:
Get CRC checksum of an NSData in Objective-C

I can't find any implementation of CRC32 algoryghm in xcode. Can anybody help me calculate it?

like image 350
Funky Kat Avatar asked Apr 02 '11 17:04

Funky Kat


1 Answers

libz has a crc32() function. To use it with NSData, try this simple category:

Your header:

@interface NSData (CRC32)
- (uint32_t)CRC32Value;
@end

Your implementation:

#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
like image 71
Jonathan Grynspan Avatar answered Nov 09 '22 15:11

Jonathan Grynspan