I have to do some work work with integers, but I am interested in treat them as binary data, in a way that for example I can take the 4 most significant bits of an 32 bit value. What I am trying to do is, I have several 32 bit value I want to take for example, in the first one 4 bits, the second one 6 bits and the last one 22 bits, and after concatenate them and get another 32 bits value.
Can anyone please recommend any library or any othe way to do this?. Thank you.
It seems that you don’t need a library for that. Just bit shifting, logical and, or and xor should be sufficient for what you want to do.
EDIT: Just to give an example. Suppose
ais a 32-bitint, and you want to take the first 4 bit and store it in the lowest bit positions in another integerb, you could do this: