Getting file contents as a hex string
Getting file contents as a hex string
- Subject: Getting file contents as a hex string
- From: Toby Atkin-Wright <email@hidden>
- Date: Sun, 23 Jan 2005 22:09:40 +0000
I want to make a string containing the first ten bytes of a file, in
hex. The following code works, but doesn't seem very elegant. Is there
a more Cocoa-style way of doing it?
NSData* theImageData = [NSData dataWithContentsOfFile:@"test.jpg"];
const unsigned char* theImageDataBytes = [theImageData bytes];
NSMutableString* theMagic = [NSMutableString stringWithCapacity:20];
int i;
for (i = 0; i < 10; i++)
{
[theMagic appendFormat:@"x", theImageDataBytes[i]];
}
Toby
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden