[futurebasic] Byte flipping

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : December 1997 : Group Archive : Group : All Groups

From: Greg_Neagle@...
Date: Tue, 09 Dec 1997 17:49:09 -0800
Following up on the need to flip numbers from MSB->LSB to LSB->MSB and vice
versa...
The application I'm working on doesn't read or write very many of these, so
speed isn't normally very important, but I thought I'd test two approaches.
Here's the code.  Approach B, while uglier, is three times faster than approach
A.

'------------------------------
LOCAL FN flipLongA&(a&)
  DIM x&
  x& = PEEK(@a&) + (PEEK(@a&+1) << 8) + (PEEK(@a&+2) << 16) + (PEEK(@a&+3) <<
24)
END FN = x&

LOCAL FN flipLongB&(a&)
  DIM x&
  POKE @x&, PEEK(@a&+3)
  POKE @x&+1, PEEK(@a&+2)
  POKE @x&+2, PEEK(@a&+1)
  POKE @x&+3, PEEK(@a&)
END FN = x&

WINDOW 1
TEXT _geneva,10
DIM startTicks&, x&, y&

PRINT "Testing FN flipLongA...."
startTicks& = FN TICKCOUNT
FOR x& = 1 TO 200000
  y& = FN flipLongA&(x&)
NEXT
PRINT "Time: " FN TICKCOUNT - startTicks&
PRINT

PRINT "Testing FN flipLongB...."
startTicks& = FN TICKCOUNT
FOR x& = 1 TO 200000
  y& = FN flipLongB&(x&)
NEXT
PRINT "Time: " FN TICKCOUNT - startTicks&
PRINT

DO
UNTIL FN BUTTON


- via BulkRate 2.6.x