[EMAIL PROTECTED] wrote:
> Ok, i'm then wondering *how* i am supposed to get to the value of a swapped
> float at all, if my method is not valid.
> My example works fine here, so i really dont know how i can make it 'better'.
>
> Thanks
>
> -------- Original-Nachricht --------
>> Datum: Sun, 20 Apr 2008 14:38:06 +0100
>> Von: "Paul Herring" <[EMAIL PROTECTED]>
>> An: [email protected]
>> Betreff: Re: [c-prog] endianness questions
>
>> On Fri, Apr 18, 2008 at 4:39 PM, <[EMAIL PROTECTED]> wrote:
>> [...]
>>> I see. Thank you. Looks like swapping those bytes isnt as
>> straightfoward as i
>>> thought:S Anways, looking at my first function, i just realised , i
>> can't actually see
>>> the problem. Even without declaring buffer as static, why should there
>> be a problem?
>>> I am returning the value of buffer, not its address.
>> Because the 'value' is not guaranteed to be valid for a floating point
>> number which may cause problems.
>>
>> --
>> PJH
>>
>> http://shabbleland.myminicity.com/tra
Don't access the _value_, just copy the bytes.
void ExtractSwappedFloat(float *MyFloat, char *Bytes)
{
char *Buffer = (char *)MyFloat;
Buffer[0] = Bytes[3];
Buffer[1] = Bytes[2];
Buffer[2] = Bytes[1];
Buffer[3] = Bytes[0];
}
--
Thomas Hruska
CubicleSoft President
Ph: 517-803-4197
*NEW* MyTaskFocus 1.1
Get on task. Stay on task.
http://www.CubicleSoft.com/MyTaskFocus/