• 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: "byte orders" question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: "byte orders" question
      • From: Koen van der Drift <email@hidden>
References: 
 >"byte orders" question (From: Koen van der Drift <email@hidden>)
 >Re: "byte orders" question (From: Ben Kennedy <email@hidden>)
 >Re: "byte orders" question (From: Koen van der Drift <email@hidden>)
 >Re: "byte orders" question (From: Scott Ribe <email@hidden>)
 >Re: "byte orders" question (From: Koen van der Drift <email@hidden>)
 >Re: "byte orders" question (From: "Glenn L. Austin" <email@hidden>)
 >Re: "byte orders" question (From: Koen van der Drift <email@hidden>)

  • Prev by Date: Re: Design Question
  • Next by Date: Re: "byte orders" question
  • Previous by thread: Re: "byte orders" question
  • Next by thread: Re: "byte orders" question
  • Index(es):
    • Date
    • Thread