Re: "byte orders" question
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