 |
|
 |
|
Next: Application Launch failure
|
| Author |
Message |
External

Since: Sep 26, 2003 Posts: 61
|
(Msg. 1) Posted: Fri Oct 13, 2006 1:55 pm
Post subject: byte swapping for floats on Intel Mac Archived from groups: comp>sys>mac>programmer>misc (more info?)
|
|
|
Hi,
we've got data in Little-endian format, which we need to convert to the
local Host format. I can't seem to find a way to do that. We've got
existing software which writes data out in Little-endian format, which may
be read on a Mac or on a PC, and now on an Intel Mac, so we need to have
code on the Mac side which will do the conversion properly in a Universal
Binary app, regardless of whether it's run on a PPC or an Intel Mac.
Here's the code I have now, but I don't think it's doing anything. I
think this just converts it from Host format right back to Host format, and
I need to convert it from Little-endian to Host format.
CFSwappedFloat32 swappedFloat = CFConvertFloatHostToSwapped(
theFloatToConvert );
return CFConvertFloatSwappedToHost( swappedFloat );
Anyone know how to do this properly?
Thanks,
-Howard >> Stay informed about: byte swapping for floats on Intel Mac |
|
| Back to top |
|
 |  |
External

Since: Aug 04, 2003 Posts: 588
|
(Msg. 2) Posted: Fri Oct 13, 2006 5:18 pm
Post subject: Re: byte swapping for floats on Intel Mac [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
In article ,
Howard wrote:
>Hi,
>
> we've got data in Little-endian format, which we need to convert to the
>local Host format. I can't seem to find a way to do that. We've got
>existing software which writes data out in Little-endian format, which may
>be read on a Mac or on a PC, and now on an Intel Mac, so we need to have
>code on the Mac side which will do the conversion properly in a Universal
>Binary app, regardless of whether it's run on a PPC or an Intel Mac.
>
> Here's the code I have now, but I don't think it's doing anything. I
>think this just converts it from Host format right back to Host format, and
>I need to convert it from Little-endian to Host format.
>
> CFSwappedFloat32 swappedFloat = CFConvertFloatHostToSwapped(
>theFloatToConvert );
> return CFConvertFloatSwappedToHost( swappedFloat );
>
> Anyone know how to do this properly?
Apple didn't provide the functions you need directly. So instead read
the float into a uint32, call CFSwapInt32LittleToHost on the result,
and convert that to float.
--
There's no such thing as a free lunch, but certain accounting practices can
result in a fully-depreciated one. >> Stay informed about: byte swapping for floats on Intel Mac |
|
| Back to top |
|
 |  |
External

Since: Jan 12, 2005 Posts: 11
|
(Msg. 3) Posted: Sun Oct 15, 2006 1:59 pm
Post subject: Re: byte swapping for floats on Intel Mac [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
Matthew Russotto wrote:
> In article ,
> Howard wrote:
> >Hi,
> >
> > we've got data in Little-endian format, which we need to convert to the
> >local Host format. I can't seem to find a way to do that. We've got
> >existing software which writes data out in Little-endian format, which may
> >be read on a Mac or on a PC, and now on an Intel Mac, so we need to have
> >code on the Mac side which will do the conversion properly in a Universal
> >Binary app, regardless of whether it's run on a PPC or an Intel Mac.
> >
> > Here's the code I have now, but I don't think it's doing anything. I
> >think this just converts it from Host format right back to Host format, and
> >I need to convert it from Little-endian to Host format.
> >
> > CFSwappedFloat32 swappedFloat = CFConvertFloatHostToSwapped(
> >theFloatToConvert );
> > return CFConvertFloatSwappedToHost( swappedFloat );
> >
> > Anyone know how to do this properly?
>
> Apple didn't provide the functions you need directly. So instead read
> the float into a uint32, call CFSwapInt32LittleToHost on the result,
> and convert that to float.
You have to be a bit careful when doing this. For example:
float myFloat = (float)CFSwapInt32LittleToHost((uint32_t)floatToSwap);
Well do the wrong thing. The type casts will *convert* the values to
floats and ints and since they have different bit patterns you will get
the wrong answer. The "correct" method is shown below which will
overlay a uint32 over the float's data bits rather then converting the
float value to an int (and vis versa).
uint32_t temp = CFSwapInt32LittleToHost(*((uint32_t*)&floatToSwap));
float myFloat = *((float*)&temp);
Michael >> Stay informed about: byte swapping for floats on Intel Mac |
|
| Back to top |
|
 |  |
External

Since: Jan 05, 2004 Posts: 474
|
(Msg. 4) Posted: Mon Oct 23, 2006 11:47 pm
Post subject: Re: byte swapping for floats on Intel Mac [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
In article ,
"Howard" wrote:
> Hi,
>
> we've got data in Little-endian format, which we need to convert to the
> local Host format. I can't seem to find a way to do that. We've got
> existing software which writes data out in Little-endian format, which may
> be read on a Mac or on a PC, and now on an Intel Mac, so we need to have
> code on the Mac side which will do the conversion properly in a Universal
> Binary app, regardless of whether it's run on a PPC or an Intel Mac.
Check out this long but useful thread:
<http://lists.apple.com/archives/carbon-dev/2006/Jul/msg00152.html> >> Stay informed about: byte swapping for floats on Intel Mac |
|
| Back to top |
|
 |  |
External

Since: May 08, 2007 Posts: 8
|
(Msg. 5) Posted: Fri Jan 12, 2007 1:00 pm
Post subject: Re: byte swapping for floats on Intel Mac [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
"Howard" wrote in message
> Hi,
>
> we've got data in Little-endian format, which we need to convert to
the
> local Host format. I can't seem to find a way to do that. We've got
> existing software which writes data out in Little-endian format, which may
> be read on a Mac or on a PC, and now on an Intel Mac, so we need to have
> code on the Mac side which will do the conversion properly in a Universal
> Binary app, regardless of whether it's run on a PPC or an Intel Mac.
>
> Here's the code I have now, but I don't think it's doing anything. I
> think this just converts it from Host format right back to Host format,
and
> I need to convert it from Little-endian to Host format.
>
> CFSwappedFloat32 swappedFloat = CFConvertFloatHostToSwapped(
> theFloatToConvert );
> return CFConvertFloatSwappedToHost( swappedFloat );
>
> Anyone know how to do this properly?
>
> Thanks,
> -Howard
I'm new to Macs but reading the docs, I thought that running PowerPC code on
Intel
chips was not a problem..
http://developer.apple.com/documentation/MacOSX/Conceptual/universal_b...ry/univ
"Rosetta is a translation process that runs a PowerPC binary on an
Intel-based Macintosh computer-it allows applications to run as nonnative
binaries." >> Stay informed about: byte swapping for floats on Intel Mac |
|
| Back to top |
|
 |  |
External

Since: Oct 03, 2004 Posts: 2243
|
(Msg. 6) Posted: Fri Jan 12, 2007 5:58 pm
Post subject: Re: byte swapping for floats on Intel Mac [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
In article ,
"Howard" wrote:
> Hi,
>
> we've got data in Little-endian format, which we need to convert to the
> local Host format. I can't seem to find a way to do that. We've got
> existing software which writes data out in Little-endian format, which may
> be read on a Mac or on a PC, and now on an Intel Mac, so we need to have
> code on the Mac side which will do the conversion properly in a Universal
> Binary app, regardless of whether it's run on a PPC or an Intel Mac.
>
> Here's the code I have now, but I don't think it's doing anything. I
> think this just converts it from Host format right back to Host format, and
> I need to convert it from Little-endian to Host format.
>
> CFSwappedFloat32 swappedFloat = CFConvertFloatHostToSwapped(
> theFloatToConvert );
> return CFConvertFloatSwappedToHost( swappedFloat );
>
> Anyone know how to do this properly?
>
> Thanks,
> -Howard
I would suggest that the way to do it _properly_ is to make it so that
the stored format is big-endian and use the functions/macros available
on all your target platforms (and just about every other one in use
today) that translate from big-endian to native.
The expedient way - which may not be very expedient depending on how
centralized your IO is - is to #ifdef up the Mac code based on which
architecture you're building for so it doesn't bother trying to swap on
x86.
--
The best intentions in the world don't make a flawed argument magically valid. >> Stay informed about: byte swapping for floats on Intel Mac |
|
| Back to top |
|
 |  |
| Related Topics: | Tool for comparing files on Mac-Intel? - Hi all, anyone know of a tool I can use for comparing source-code files (or any text files, for that matter, on a line-by line basis) that runs on the Mac-Intel platform? On my PPC Mac, I use CodeWarrior, which has an excellent file-or-folder...
modify OS X keyboard mappings - Hello, I need to have access to the french characters. I can do this with the Canadian - CSA keyboard. However, that keyboard has a "," as a decimal. I need a ".". Changing it in the international control panel does not change...
Shared memory - Hello all, If you're not on the beach maybe you can give me a little help. I need to implement shared memory between my application and a helper tool. At first I tried CFMessageProts. This works, but if you transport huge amounts of data the data get al...
mouse freeze - My mouse has started to freeze on booting (OS 9.03). The problem is intermittent, after touching the mouse it sometimes moves just slightly and freezes again. Can someone help? Boris vainerb@access4less.net
Can ZBasic still run on Mac OSX??? - Hi all, I was going through some older floppies and ran across some of my programs from high school written in ZBasic on the old mac classic. Is it possible to find a copy of ZBasic that'll run on a Powermac G4 with OSX Jaguar? I know this app probabl... |
|
You can post new topics in this forum You can reply to topics in this forum You can edit your posts in this forum You can delete your posts in this forum You can vote in polls in this forum
|
|
|
|
 |
|
|