Re: "byte orders" question
Re: "byte orders" question
- Subject: Re: "byte orders" question
- From: Scott Ribe <email@hidden>
- Date: Sat, 26 Nov 2011 14:23:06 -0700
On Nov 25, 2011, at 9:38 PM, Koen van der Drift wrote:
> Here is what I am doing, I read an NSString from the raw data, an xml file using NSXMLParser. This works ok. Then I convert that to an NSData object, and perform base64 decoding
No, you're not ;-) You read a string that is presumably already Base64 encoded, then you stuff it into an NSData, then you Base64 encode that, then you decode it, leaving you with the original Base64 encoding intact...
Instead of:
> NSData *data = [string dataUsingEncoding:NSASCIIStringEncoding];
> NSString *base64String = [data base64EncodedString];
> NSData * base64DecodedData = [NSData dataFromBase64String:base64String];
I think you just need:
NSData * base64DecodedData = [NSData dataFromBase64String:string];
The actual byte-swapping code looks OK:
> for (n = 0 ; n < (2 * count) ; n++)
> {
> ((u_int32_t *) result)[n] = ntohl((u_int32_t) ((u_int32_t *) dataToConvert)[n]);
> }
Although there's a superfluous cast there that might be a clue that you're just slinging code in without understanding it...
There's also probably not much point to using subdataWithRange instead of bytes...
--
Scott Ribe
email@hidden
http://www.elevated-dev.com/
(303) 722-0567 voice
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden