Forum Navigation
You need to log in to create posts and topics.

Re: Mac Number conversion (LSB/MSB)

Posted by: gadams <gadams@...>

<Heres one for the thinkers...I need a couple of functions (my brains in a
<fog lately...).

<I am reading a file which has binary numbers stored in LSB/MSB format so
<some bytes read in will look like this :

<73 0 0 0 27 01 0 0

MSB) and then 27
<01 0 0 is the second one. If memory serves right, the Mac stores in MSB/LSB.

<I just bet someone has a real fast efficient way of turing those digits
<around (they are in binary in the file). If I was still in Z80, I'd do a
<rotate thru the carry. I'm not.

<But I have a lot of processing to do with longs and words stored in this
<format.

<Suggestions?

<Mel Patrick - theWabbitGuy - mel@intergate.bc.ca

I don't know if this is the fastest way to do this but it works.
Read in the variable from the file and convert it with one of these two
functions.

CLEAR LOCAL
DIM sourceVar
DIM destVar
LOCAL FN flipBytesShort (sourceVar)
'DOS format to Mac
POKE VARPTR(destVar),PEEK(VARPTR(sourceVar)+1) ' second byte to first pos
POKE VARPTR(destVar) +1,PEEK(VARPTR(sourceVar))'first byte to second
END FN = destVar
CLEAR LOCAL
DIM sourceVar&
DIM destVar&
LOCAL FN flipBytesLong& (sourceVar&)
'DOS format to Mac
POKE VARPTR(destVar&),PEEK(VARPTR(sourceVar&)+3)' 4th byte to 1st pos
POKE VARPTR(destVar&) +1,PEEK(VARPTR(sourceVar&)+2)'3rd byte to 2nd
POKE VARPTR(destVar&) +2,PEEK(VARPTR(sourceVar&)+1)' 2nd byte to 3rd pos
POKE VARPTR(destVar&) +3,PEEK(VARPTR(sourceVar&))'1st byte to 4th
END FN = destVar&
George Hacker Adams