I've read some discussions, searched Google, tried pack, unpack,
bin2hex, explode, implode, and I just can't figure out how to convert
this data. I am trying to read a file with the following format (two
examples).
41 6D 74 72 61 6B 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 75 05 1A 00
41 6D 74 72 61 6B 20 4F 6E 6C 69 6E 65 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 8F 05 2B 00
The first 28 bytes are a 00 terminated character string (in this case
"Amtrak" and "Amtrak online")
Next are the location (offset) of an entry in another file (2 bytes),
followed by that entry's size in the file (the next 2 bytes). The above
examples are key entries in an index file pointing to variable sized
entries in a data file.
I am using fread to put each field into a string variable (28 bytes, 2
bytes, and 2 bytes). The binary values are "Little Endian" (right?). In
other words 75 05 is really x0575 and 1A 00 is really x001A. I am having
the most trouble with these (I've already used bin2hex, but I don't know
how to convert the little endian to decimal.)
1. I want to strip the 00's from the string.
2. I want to convert the location (offset) into an integer variable.
3. I want to convert the size into an integer variable.
I am going to use location and size to fseek and fread the entries in
the data file into another string.
My actual goal is to transfer this data (the string and it's associated,
variable sized text field) into a MySQL database.
My guess is (was) that this is easy, but I just can't figure it out.
Any help would be very much appreciated.
TIA.
--
*****************************
Chuck Anderson • Boulder, CO
http://www.CycleTourist.com
Integrity is obvious.
The lack of it is common.
*****************************