I have come across a problem I cannot seem to solve.
I have a type of file “ASDF”, and in their header I can get the necessary information to read them. The problem is that one of the “fields” is only 4 bits long.
So, lets say it’s like this:
- From bit 0 to 8 it’s the index of the current node (I’ve read this already)
- From 8 to 16 it’s the index for the next node (Read this as well)
- From bit 16 to 20 Length of the content (string, etc..)
So my problem is that if I try to read the “length” with a bytereader I will be losing 4 bits of information, or would be “4 bits off”. Is there any way to read only 4 bits?
You should read this byte as you read the others then apply a bitmask of 0x0F
For example
this will preserve the lower four bits in the result.
if the needed bits are the high four then you could apply the shift operator