• 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 17:06:53 -0700

On Nov 26, 2011, at 4:17 PM, Koen van der Drift wrote:

> I'm pretty sure I messed up something. One of the reasons I posted it here :)
>
> After spitting through the internets, what I am using now is this:
>
> 	NSData *base64DecodedData = [NSData dataFromBase64String: @"Q5YIjESWO5JDlpIbRzMVL0OW="];
>
> 	for (NSInteger n = 0; n < 4; n++)
> 	 {
> 		u_int32_t value;
>                [base64DecodedData getBytes: &value range: NSMakeRange( n*4, sizeof( u_int32_t ) )];
>
>                u_int32_t result = CFSwapInt32HostToBig( value );
>                NSLog(@"%u", result);
> 	}
>
> This gives:
>
> 1133906060
> 1150696338
> 1133941275
> 1194530095
>
> This correspond to the values I am getting using the unpack function in a Perl script that does what I need, so I think I am on the right track. The perl script continues with $float = unpack("f", pack("I", $i));,  where $i is one of the four numbers above.  This gives the expected values for the floats.  So I may not need the ntohl() function at all.
>
> Now I need to figure out how to go from u_int_32 to float.

I think what you had before would work for the byte swap & conversion, assuming that your "result" was an array of floats; CFSwapInt32HostToBig is not really the right call--when it works it is by accident.

--
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>)
 >Re: "byte orders" question (From: Scott Ribe <email@hidden>)
 >Re: "byte orders" question (From: Koen van der Drift <email@hidden>)

  • Prev by Date: Re: "byte orders" 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