Trying to Swap Byte on Floats
Trying to Swap Byte on Floats
- Subject: Trying to Swap Byte on Floats
- From: "Peter J. Molfese" <email@hidden>
- Date: Thu, 21 Jun 2007 01:40:46 -0400
Hi all-
I know that I'm missing the simple answer on this, but I'm trying to
read float values out of a binary file. The binary file was encoded
using a PowerPC big-endian format. I'm reading the binary file on an
Intel-mac and trying to do the swapping of bits.
My code worked when I was running in Rosetta as follows:
int file_location = 26;
float SSR = *((const float *)([myFile bytes] + file_location));
file_location += 4;
Now on the intel-mac side in the conversion I've attempted the
following:
1. Simple approach:
float SSR = EndianS32_BtoN(*((const float *)([myFile bytes] +
file_location)));
2. Round-about:
float tempSSR = *((const float *)([myFile bytes] + file_location));
float SSR = NSConvertSwappedFloatToHost(NSConvertHostFloatToSwapped
(tempSSR));
Approach #1 seems to give me a lot of numbers that are either 0 or
very very small 1.2*10-13. Approach #2 gives me the same numbers as
if I didn't swap the bits at all. Is there an easy way to read in
the big-endian floats and convert them to little-endian that I'm
missing?
Thanks,
Pete
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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