If you want to convert a program to hexdecimal or binary out, here is two programs to do so.

First get your pre-reqs:

Note: these programs would work outside of linux, just need to make sure you have the bitstring python module installed.

EXAMPLE OUTPUT

Imagine a source file, that will be our input file for the tohex/tobin programs, that looks like this:

binary output:

hexadecimal output:

SIMPLE PROGRAMS

Now here is a simple version of converting to hex:

And here is the simple version of converting to binary:

BLOCKSIZE INFO

Note about blocksize: the blocksize, BS, is set to 4096, I find thats a good amount to read in while keeping the program fast. I converted a 1MB file in a tenth of a second with blocksize of 4096 bits, but it took 4 seconds with a block size of 128 bits, and 17 seconds with a 32 bit block size. Reading in a byte at a time (blocksize is 8 bits) took 44 seconds to process the 1MB file.

Caveat: Had to drop the block size to 8, which is the size of a byte, or else this wouldn’t work on inputfiles that are less than the blocksize in size (as a ReadError would incur). Likewise for files that are not even blocksize integer size will get truncated at blocksize integers. With setting block size to 8 we fix that problem at the cost of performance

THE REAL PROGRAMS

Now if you want a fancy program, that can have helpful info, and print on the desktop pretty and can handle errors, then use the programs below.

Hexadecimal / hex version:

Binary version:

The end.

Leave a Reply

Your email address will not be published. Required fields are marked *