In C / C ++, is there an easy way to apply bitwise operators (in particular, left / right shifts) to dynamically allocated memory?
For example, let's say I did this:
unsigned char * bytes=new unsigned char[3];
bytes[0]=1;
bytes[1]=1;
bytes[2]=1;
I would like to do this:
bytes>>=2;
(then "bytes" will have the following meanings):
bytes[0]==0
bytes[1]==64
bytes[2]==64
Why should the values be like this:
After allocation, the bytes are as follows:
[00000001][00000001][00000001]
But I am looking for processing bytes as one long string of bits, for example:
[000000010000000100000001]
A correct shift of two will cause the bits to look like this:
[000000000100000001000000]
Which, in the end, looks like this when they are separated back by 3 bytes (thus, 0, 64, 64):
[00000000][01000000][01000000]
? / ? : , ? . ( ) .