My program going to be getting a stream of bytes, currently from a file that will be read using a binary mode istream. In order to use the data I will need to use the individual bits later in the program. Currently there are three things that I am unsure about, reading the information from the file, processing it and storing it for later. The processing is the part that I am most unsure about, the other two are minor queries.
For receiving the data a binary istream is currently being used is there a faster way to receive the data? For storing the data I was going to use a bool vector as the size will not be known at compile time and it could expand up to a couple of MB of data, is there a better way to store the data? There will be another process that could use a relatively large amount of memory before the bits are needed if this matters to the storage.
The last problem, and the one causing me the most bother, is how to split the byte into bits since this will be in a loop with a large amount of data I would like this to be efficient as possible. The first idea, and the one that I am currently favouring, is to use bitwise & to check if the bit is set and then a comparison to set the bool;
bitbool = (byte&128) != 0
The next method is to right shift and then left shift to leave the most significant bit, then shift to leave the two most significant and use the previous one to isolate the second most significant, however I think that this will be less efficient than the previous method.
The final method would be to use an eight wide bitset to convert the byte then read out the bits and set the bools. I am not sure about bitsets as I haven’t used them before although after my research it appears possible to use them for this purpose I am not sure how efficient it would be.