[futurebasic] Re: [FB] ByteSwapping dim as Single

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : March 2008 : Group Archive : Group : All Groups

From: David Bailey <dbail@...>
Date: Tue, 11 Mar 2008 14:55:35 -0700
OK this may be a case of a little knowledge being a dangerous thing.

Brian indicated that there are calls in the CFByteOrder.incl file to  
deal with singles/float/real but they (two float routines) do not seem  
to convert Host singles to Big singles.  Here is where I stepped into  
danger.

I assumed I could work with each word of the 4 byte single separately  
and reverse them.  This code snippet

-------------------------
#if def _fbtoc

DIM x,y
'work on first two bytes or word
x = PEEK WORD(@Pref.NotePageWidth!)
'work on next two bytes or word
y = PEEK WORD(@Pref.NotePageWidth!+2)
'byte swap the first variable/word
x = fn CFSWapInt16HostToBIg(x)
'byte swap the second varialbe/word
y = fn CFSWapInt16HostToBIg(y)
'replace the swapped variables first to last and last to first
poke word @Pref.NotePageWidth! + 2,x
'replace the swapped variables first to last and last to first
poke word @Pref.NotePageWidth! ,y
'print to see if it worked
print Pref.NotePageWidth!

#else

print Pref.NotePageWidth!

#endif
---------------------------

receives a value of 5.5 when compiled in FB and reading a record from  
a particular test resource.  If compiled in FBtoC the value returned  
is correct in this example and others I have tried.  Am I just lucky  
here or can you manipulate individual words/values in a variable and  
then reverse them.??

Thanks

David