Analyzing the Binary Input Files

The Multifloria DMV is unable to generate text equivalents for the binary input files, due to the incompetence of their COBOL programmers. However, it is possible to learn something about their structure by "dumping" them using the od ("octal dump") command. Despite its name, od will dump in many formats, notably ASCII and hexadecimal.

For example, the command:

    od -xc simplesparc.bin
will show you the contents of simplesparc.bin in both hexadecimal and character form. It is generally easier to interpret the Sparc version than the Intel one, unless you are already expert at that sort of thing. You may wish to ask for help from the graders or professors in interpreting these dumps.

As an example, here are the first few lines of "od -xc simplesparc.bin" (this command must be executed on Turing to get the correct results):

0000000    694d    0012    d687    0000    000f    4765    6f66    6620
           i   M  \0 022 326 207  \0  \0  \0 017   G   e   o   f   f    
0000020    4b75    656e    6e69    6e67    0001    0107    8269    4e00
           K   u   e   n   n   i   n   g  \0 001 001 007 202   i   N  \0
0000040    74cb    b100    0000    0c4a    6f6e    2053    7472    6175
           t 313 261  \0  \0  \0  \f   J   o   n       S   t   r   a   u
0000060    7373    0002    0e07    9869    4c00    12d6    8700    0000
           s   s  \0 002 016 007 230   i   L  \0 022 326 207  \0  \0  \0
0000100    1547    656f    6666    204b    7565    6e6e    696e    6727
         025   G   e   o   f   f       K   u   e   n   n   i   n   g   '

Here, we can see that the first character (the command) is an 'i' (insert new driver). The prefix for the license number is 'M'. The next four bytes are the license number, shown in hexadecimal: 0012d687. You can use a calculator to convert this to its decimal equivalent, 1234567. Then come 4 more bytes giving the length of the name string, again in hex: 0000000f, or 15 characters, and then the driver's name, followed by a null byte (00, or \0 as a character). Then are two single bytes giving the birth month (01) and birth day (01), followed by a pair of bytes that together give the birth year (0782 in hex, or 1922 decimal). That's the end of the first record; the next thing in the input is the 'i' command for the second driver.

Converting Hex to Decimal

Many modern calculators include a feature that will convert hexadecimal numbers to decimal and vice versa. There are also several programs available under Unix. Two of them are dc ("desk calculator") and bc. Dc is an RPN-style calculator. To convert hex to decimal, start dc and then type "16i" to tell it you're typing hex numbers. Then type the number you want to convert, using uppercase for the digits A-F, and follow it with the letter "p". Finally, type "q" to quit. For example:

    % dc
    16i
    12D687
    p
    1234567
    q
    %

Bc will do the same thing, but it uses a non-RPN input format. Start up bc and type ibase=16 as the first line, to tell it you are typing hex numbers. Then whenever you type something in hexadecimal, it will respond with the decimal equivalent. Again, you must use uppercase characters for the digits A-F.


© 2001, Geoff Kuenning

This page is maintained by Geoff Kuenning.