I am working on a project that requires reading in large amounts of data from a binary file. The issue is that I have to be able to read different binary formats depending on the source. All of the data is 16 bit integers stored in a binary file but it could be twos-compliment or unsigned, big endian or little endian, most significant bit first or least significant bit first.
I know that fread will allow you to set the endianess and signed/unsigned, but taking care of the bit order is what is tripping me up.
The following is what I have for signed/unsigned and big/little endian:
sampleChunk = fread(fid, chunkSizeSamples, 'int16=>single','ieee-be');
sampleChunk = fread(fid, chunkSizeSamples, 'int16=>single','ieee-le');
sampleChunk = fread(fid, chunkSizeSamples, 'uint16=>single','ieee-be');
sampleChunk = fread(fid, chunkSizeSamples, 'uint16=>single','ieee-le');
However, there are four more possibilities if the least significant bit is first that I do not know how to handle without costly bit flipping routines. Does anyone have any suggestions to be able to easily read the eight different formats.
Just to be clear since endianess sometimes has different meaning, I am concerned with both byte ordering (endianess) and bit ordering.