in reply to Re: Converting Files
in thread Converting Files

You are exactly right! There may be some special cases that will throw your

unpack('C*', $buf);

off. Mainly, when you have a binary file there can be BCD (Binary Coded Decimal) contained within. This would generally be used for a float data type (money or fractional data). There also may be encoded date fields (generally they consist of 2 bytes).

Also watch out for multiple byte hex numbers. i.e. you have 2 bytes 0x01 and 0x02, but a multiple byte hex number will append those two and convert to decimal. (0001 0010) == (18)

Finally some binary files will contain pointers (a.k.a memory locations) to other locations in the same file or other files. If this is the case you will need to be able to handle that pointer so that you do not lose any data.

I would suggest first, parsing the file as samizdat has suggested. Most likely you will find garbled fields after you are done. These garbled fields will probably fall into one of the categories I have mentioned. From there on out, you become Sherlock Holmes and try to determine what each one of them is.

Some tools to help you look at the binary data are hexdump or a combination of dd + hexdump (if you know the block-size of each record).

i.e. (dd if=binaryfile bs=blocksize | hexdump -c | more)

If you are using a *nix variant that is. If you do not have a *nix OS, then install cygWin and use it for these command line tools.