I need to extract certain bit ranges with a long value, for example:
long input = 15367 (11110000000111)
What I need to do is extract two long values from the original long,
First long is 5 bits starting from bit 0, so bits 0:4 = 7 (0111) Second long is 56 bits starting from bit 8, so bits 7:55 = 60 (1111000)
I know that this can be done using bit shifting and masking, however, I'm not quite sure how to implement this so that it is dynamic every time, since every time I need to do this, the long ones will be different, and therefore will also be specific bit ranges.
I read about BitSets and BitArrays, however I'm not quite sure if these are the right things to work.
Any advice on the best way to implement it is welcome.
Thanks!
java binary logical-operators bitmask
Tony
source share