rdg
12-14-2006, 08:46 PM
I try to *parse* a binary file.
I know that the file is a series of 16-bit big-endian words.
I am not sure what to do :argh:.
theFile = fopen myFile "rbS"
re_1 = ""
while re_1 != undefined do(
re_1 = (readlong theFile #signed)
if re_1 != undefined then (
format "%\n" re_1
)
)
I try to "swap the words" with this:
fn longSwap s = (
b1 = bit.and s 255
b2 = bit.and (bit.shift s 8) 255
b3 = bit.and (bit.shift s 16) 255
b4 = bit.and (bit.shift s 24) 255
return ((bit.shift 24 b1) + (bit.shift 16 b2) + (bit.shift 8 b3) + b4)
)
But I get errors like this:
Runtime error: Bit index or shift count out of range: < -32 or > 32: 102.
I I read just every second byte I get most of the data I need.
Some of the data wont show up right as the values are to big :) -> 16-bit words.
Maybe someone sees my error.
Or can point me to a "101 byteswapping for dummies like rdg".
As I know know almost anything about endians, but don't know how to use them ...
Georg
I know that the file is a series of 16-bit big-endian words.
I am not sure what to do :argh:.
theFile = fopen myFile "rbS"
re_1 = ""
while re_1 != undefined do(
re_1 = (readlong theFile #signed)
if re_1 != undefined then (
format "%\n" re_1
)
)
I try to "swap the words" with this:
fn longSwap s = (
b1 = bit.and s 255
b2 = bit.and (bit.shift s 8) 255
b3 = bit.and (bit.shift s 16) 255
b4 = bit.and (bit.shift s 24) 255
return ((bit.shift 24 b1) + (bit.shift 16 b2) + (bit.shift 8 b3) + b4)
)
But I get errors like this:
Runtime error: Bit index or shift count out of range: < -32 or > 32: 102.
I I read just every second byte I get most of the data I need.
Some of the data wont show up right as the values are to big :) -> 16-bit words.
Maybe someone sees my error.
Or can point me to a "101 byteswapping for dummies like rdg".
As I know know almost anything about endians, but don't know how to use them ...
Georg
