• 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: Greg Guerin <email@hidden>
  • Date: Sat, 26 Nov 2011 17:17:05 -0700

Koen van der Drift wrote:

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);


Since you're just doing a memcpy(), you can simply cast the bits and avoid the copying. Try this:

float f = *((float*) &res);

Or try defining a C union:

union foo {  float f;  u_int32_t u;  };
union foo bar;
bar.u = CFSwapInt32HostToBig(value);
float f = bar.f;

  -- GG

_______________________________________________

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: Kyle Sluder <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