[futurebasic] Re: Mac Number conversion (LSB/MSB)

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

From: tedd <sperling@...>
Date: Tue, 9 Dec 1997 08:03:29 -0500
>>Unless there is something that I'm not understanding, I would leave them
>>where they are and do my processing accordingly. For what reason do you
>>need to turn them around?
>
>Imagine your plotting data on an X/Y grid and those are the coorindinates.
>Swapping an MSB and LSB could prove to be an interesting plot...
>
>Mel Patrick - theWabbitGuy - mel@...
>http://www.intergate.bc.ca/business/mel

Mel:

It would be _if_ you processed the numbers incorrectly. I'm talking about
leaving the data in memory "as is" and then processing it "in place".
Moving data takes time. The following is some code I wrote to process data
stored in LSB order.

LOCAL FN readByte             'read 1 byte
  DIM a
  a = PEEK ( [gDataH&] + gOffSet&)
  INC (gOffSet&)
END FN = a

LOCAL FN readUnSignedByte     'read un-signed byte
  DIM a
  a = FN readByte
  IF a < 0 THEN a = 256 + a
END FN = a

LOCAL FN readSignedByte       'read 1 byte and make signed byte
  DIM a
  a = FN readByte
  a = a - 127
END FN = a

LOCAL FN readInteger         'read 2 bytes integer value in LSB order
  DIM a
  a = (FN readByte) + (FN readByte <<8)
END FN = a

LOCAL FN readMedInteger      'read 3 bytes med integer in LSB order
  DIM a&
  a& = (FN readByte) + (FN readByte <<8) + (FN readByte <<16)
END FN = a&                  'return long integer value

LOCAL FN readLongInteger     'read 4 bytes long integer in LSB order
  DIM a&
  a& = (FN readByte) + (FN readByte <<8) + (FN readByte <<16) + (FN
readByte <<32)
END FN = a&                  'return long integer value

LOCAL FN readReal            'read 6 bytes long integer in LSB order
  DIM a!
  a! = (FN readByte) + (FN readByte <<8) + (FN readByte <<16) + (FN
readByte <<32) + (FN readByte <<64) + (FN readByte <<128)
END FN = a!


Hope this helps.

tedd

_____________________________________________________________________
tedd f. sperling                       <mailto:sperling@...>
                                     http://www.sojourn.com/sperling/