• 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
Re: Quick way to convert hex string represented in ASCII to binary?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Quick way to convert hex string represented in ASCII to binary?


  • Subject: Re: Quick way to convert hex string represented in ASCII to binary?
  • From: Aaron Burghardt <email@hidden>
  • Date: Sun, 30 Jul 2006 09:34:16 -0400

It sounds like you have a workable solution, but if you want to experiment a little for performance reasons, you have a couple other options.

The openssl included with OS X has base64 encoding/decoding functions. IIRC, base64 converts every 2 bytes of data to 3 ASCII characters, so the encoded data would be more compact than hex strings. Raw email typically uses base64 for attachments, so you can look there for an idea of what the output looks like, or use openssl in Terminal to convert test files. Note, to use openssl in you app, you have to add -lcrypt to the Other Linker Flags build setting. A quick Google also found this:

http://www.dribin.org/dave/blog/archives/2006/03/12/base64_cocoa/

If you require hex, the family of printf and scanf functions in the C library may be more efficient. In Terminal, 'man printf' and 'man scanf' will provide you details.

HTH,

Aaron

On Jul 29, 2006, at 4:40 PM, Ken Tozier wrote:

Well none of this stuff worked so I ended up writing my own categories, NSData unicharHexStringFromData and NSString dataFromUnicharHexString that convert and restore NSData into unicode hex strings. I can send them through HTTP to PHP scripts without error, save them in a database, call them back and convert them back to NSData. May not be the most elegant solution but it's the only thing that worked. Even NSData description messed with data in a way that was impossible to restore.

Ken

_______________________________________________ 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
References: 
 >Fwd: Quick way to convert hex string represented in ASCII to binary? (From: Ken Tozier <email@hidden>)
 >Re: Quick way to convert hex string represented in ASCII to binary? (From: Andreas Mayer <email@hidden>)
 >Re: Quick way to convert hex string represented in ASCII to binary? (From: Ken Tozier <email@hidden>)

  • Prev by Date: AppleScript from Cocoa applications
  • Next by Date: Re: AppleScript from Cocoa applications
  • Previous by thread: Re: Quick way to convert hex string represented in ASCII to binary?
  • Next by thread: Sorting NSTableView
  • Index(es):
    • Date
    • Thread