[futurebasic] Re: [FB] a few FBtoC questions

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

From: Robert Purves <listrp@...>
Date: Wed, 17 Sep 2008 12:51:51 +1200
Mark Chappell wrote:

> Another issue I'm facing is Endian.  I and a lot of users of my  
> programs have boatloads of data files comprised mainly of single- 
> precision floats.   All of these are stored in 'classic' big-endian  
> format on disk.  Some of the files are large (upper limit is 24 data  
> channels with 4 million samples per channel).   FBtoC faultlessly  
> uses the READ FILE# command to get these off the disk and into an  
> array but of course all values have endian errors.
>
> What's the simplest way to convert these large arrays of floating- 
> point values into Intel-readable byte order?   I poked around in the  
> Tlbx CFByteOrder.incl and Subs FloatByteSwapping.incl  in the  
> Headers folder but did not come away sufficiently enlightened.

include "Subs FloatByteSwapping.incl"
dim as single value
// read big-endian value from disk
//read #1, value
value = fn SwapSingleBigToHost!( value )
// value is now host-endian, ready for use
//...
value = fn SwapSingleHostToBig!( value )
// write big-endian value to disk
//write #1, value

This code works in PPC and Intel, FB4 or FB5.
If your project is FBtoC-only, you can remove the ugly '!' suffices  
from the swapping functions.

Robert P.