| |||
| [Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] |
On Jun 7, 2006, at 7:14 PM, David Alger wrote:
Thanks Steve,
The code sample you gave looks great and I'll put it to good use.
I had thought that this was the case but wasn't quite sure, as I have never dealt with endian issues before.
steve
On Jun 7, 2006, at 8:44 PM, Steve Christensen wrote:
On Jun 7, 2006, at 6:00 PM, David Alger wrote:
I have some structs that I write/read to and from disk, and they have > 1 byte variables that need to be swapped.
My question is would you swap a type 'float' var just as you would a UInt16?
Yes, since the byte ordering is likewise reversed. You just have to be careful that an unexpected type conversion doesn't occur when copying the float into a UInt32 so that it can be swapped. Maybe do something like this?
inline float SwapBigEndianFloatToHost(float unswappedFloat) { #if defined(__BIG_ENDIAN__)
return unswappedFloat;
#else
union { float fFloat; UInt32 fFloatAsUInt32; } swapper;
swapper.fFloat = unswappedFloat;
swapper.fFloatAsUInt32 = CFSwapInt32BigToHost (swapper.fFloatAsUInt32);
return swapper.fFloat;
#endif }
_______________________________________________ Do not post admin requests to the list. They will be ignored. Carbon-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/carbon-dev/email@hidden
| References: | |
| >Swapping variables of type float (From: David Alger <email@hidden>) | |
| >Re: Swapping variables of type float (From: Steve Christensen <email@hidden>) | |
| >Re: Swapping variables of type float (From: David Alger <email@hidden>) |
| Home | Archives | FAQ | Terms/Conditions | Contact | RSS | Lists | About |
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE
Contact Apple | Terms of Use | Privacy Policy
Copyright © 2007 Apple Inc. All rights reserved.