I have a protocol guide for a piece of hardware where I can extract 16 different kinds of data. To indicate I want all data, I would enter 65535 as the mask.
2^0 (1) + 2^1 (2) + 2^2 (4) ... + 2^15 (32768) ============== 65535 I now need to indicate I need options 9, 10, and 13. Presumably I simply need to use the following calculation:
2^9 (512) + 2^10 (1024) + 2^13 (8192) ============== 9728 (If I'm off-base here, or there is a programmatic way to do this, I'd be interested to know!)
What I would like to know is how I would in future extract all the numbers that were involved in the summation.
I had thought I would be able to check with (9728 & 9) == 9, (9728 & 10) == 10, and (9728 & 13) == 13, but all those return false.
<<, e.g.2**9 == 1 << 9, 2**13 == 1 << 13