Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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



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: http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

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>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.