I am quite comfortable with the idea of using bit masks to test variables for specific values. What came up the other day is the need to test a byte for the presence of only a single set bit, where the specific bit is not known.
I wanted to know whether the byte had any of the following values, without caring what the actual value was;
00000001 00000010 00000100 00001000 00010000 00100000 01000000
The consensus from everyone I’ve discussed this with is that a loop with multiple tests is required, but I can’t help thinking that out there somewhere is someone that has a clever bit mask or mathematical way to test for this with a single expression.