Re: looking for a crc code
Re: looking for a crc code
- Subject: Re: looking for a crc code
- From: Chris Suter <email@hidden>
- Date: Mon, 16 Jun 2008 10:23:01 +1000
On 15/06/2008, at 3:49 AM, Michael Hall wrote:
On Jun 14, 2008, at 10:25 AM, Jens Alfke wrote:
On 14 Jun '08, at 4:59 AM, Ilan Volow wrote:
No mention at all I can find (in the 20 seconds I scanned the
first two result pages) of any cocoa CRC implementations. If a
newbie were to do a search like this and turned up such a
fruitless list of leads, I wouldn't be surprised in the least
that they came to the list and asking for a personal
recommendation of some hard-to-find Cocoa framework from
experienced Cocoa programmers.
Yes, but what does CRC have to do with Cocoa? It's just a function
that takes a pointer and a length and returns an int. It'd be
trivial to use any C implementation in a Cocoa app, so there's no
reason to restrict the search by adding "cocoa" as a keyword.
I googled up this one. Might of taken more than a minute I'm afraid.
Checksum, Please
http://yamacdev.blogspot.com/2006/12/checksum-please.html
It suggests zlib which should always be available, shouldn't it?
#import <Cocoa/Cocoa.h>
# include <sys/types.h>
#include <zlib.h>
int main(int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
unsigned long crc = crc32(0L, Z_NULL, 0);
char * test = "TEST";
crc = crc32(crc,test,4);
fprintf(stdout,"crc=%i\n",crc);
}
compiled with...
gcc -framework Cocoa -lz -o testcrc testcrc.m
(Note the -lz for zlib also find some copy of zlib.h for more info
on the crc32() method or a adler or other zlib supported alternative)
Unfortunately, testing got sort of inconsistent results.
./testcrc
crc=-286616648
doesn't seem to work out quite the same as...
crc32 test.txt
f783d7be
(man crc32, it appears to be the tcl version mentioned in the blog
above.).
The crc's as far as I know should be the same here, so not quite
sure what the deal is there, but zlib crc's I think should always be
available.
They are the same. The problem is that your test.txt file includes a
line-feed in it. The other thing that might be confusing you is that
you're using %i as the format specifier when you probably want to use
%x, or strictly speaking, %lx since you’re passing in a long.
- Chris
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden