c++ - arbitrary void* chunk to bitset

354 views Asked by At

Suppose I have a method that receives a buffer of fixed lenght, like this:

#define SIGN_SIZE 64

bitset<SIGN_SIZE> chunkToBitset(void * chunk);

Now, what I want is to create a bitset from the bits of that chunk of data (the size of the chunks is always 128 bits [16 bytes]) limited by SIGN_SIZE, where SIGN_SIZE can be any value in (32, 64, 96 or 128).

I tried to cast the chunk to unsigned long, but It does not seems to return the right value. Example:

unsigned long ulon = (unsigned long)* chunk;
bitset<SIGN_SIZE> bs(ulon);

And this approach could only work when SIGN_SIZE is 64, if it is 96 it does not work.

How can I construct the bitset with all the bits in chunk but respecting the limit SIGN_SIZE? Preferably not setting bit per bit.

Appreciate the help!

0

There are 0 answers