The C-code snippet below is something I wrote to read a hex character from a file and convert each bit into a sample of byte length. Because how my hex file was written I had to decode even characters before the odd ones, you’ll notice in the code. If you need something similar feel free to tweak the code below.

Example:
Input hex file format (filename.dat):

1234

Output file format(filename.bin):

00 01 00 00 01 00 00 00 01 01 00 00 00 00 01 00

If you notice the converter takes the even character first and reads LSB to MSB and then reads the previous odd character (LSB to MSB) and so on…
There are many ways of doing this in C or Python but MATLAB is not one of them! Why? Because it is just too SLOW.
This is a good binary file reader.