• 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: Charles Srstka <email@hidden>
  • Date: Sat, 26 Nov 2011 17:37:21 -0600

If the source code that is sending you the data in the first place is your own code, you could have that code use the CFConvertFloat32ToSwapped() before sending it, and then your client can use CFConvertFloat32SwappedToHost() to convert it back, nice and easily.

At any rate, HostToBig is not what you want in the client, since you’re swapping it *to* the host byte order, not *from* it. CFSwapInt32BigToHost() would be more correct in that case, even though the two functions will both do the same thing in practice on a little-endian machine.

Charles

On Nov 26, 2011, at 5:24 PM, Koen van der Drift wrote:

>
> On Nov 26, 2011, at 6:17 PM, Koen van der Drift wrote:
>
>> Now I need to figure out how to go from u_int_32 to float.
>
>
> I think I figured it out:
>
> 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 res = CFSwapInt32HostToBig(value);
>
>                float f;
>
>                memcpy(&f, &res, sizeof(f));
>                NSLog(@"%f", f);
>
>            }
>
> This gives the expected four float values.
>
> Does this look ok, or did I overlook something?
>
> Thanks,
>
> - Koen._______________________________________________
>
> 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

_______________________________________________

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

  • Prev by Date: Re: "byte orders" question
  • Next by Date: Preventing Doc based apps from creating docs
  • Previous by thread: Re: "byte orders" question
  • Next by thread: Re: "byte orders" question
  • Index(es):
    • Date
    • Thread