Sunday, June 3, 2012

iOS: NSString to and from Binary Data

From Binary to String

If binary data is in NSData:
NSString *theStr = [[NSString alloc] initWithData:theData encoding:NSUTF8StringEncoding];

If it is in a char[]:
NSString * theStr =[[NSString alloc] initWithBytes:theBytes length:numBytes encoding:NSUTF8StringEncoding];

From String to Binary

NSData *theData = [theStr dataUsingEncoding:NSUTF8StringEncoding];


References

No comments:

Post a Comment