• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Getting file contents as a hex string
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Prev by Date: Re: Couple of questions about the "SEL" datatype
  • Next by Date: Re: Manual binding questions.
  • Previous by thread: Fullscreen windowing and NSMovieView.
  • Next by thread: Re: Font With NSBezierPath Help
  • Index(es):
    • Date
    • Thread