if you want specifically to test for 1001 and 9, and 9 only, then do you want 11, 13, and 15 to fail?
In which case "and"ing with 9 is not sufficient, since 11 and 9 will also return 9.
So 1001 is 9
1011 is is 11
1101 is 13
1111 is 15
all of these return 9 when "and" ing with 9. If you want to test that only bits 5 and 8 are set it's not so easy.
xor will work for values from 1 to 15, but won't work for values with the large bits set.
mynumber xor 9 = 0 tests for 9 and only 9. (ie 1001)
But it doesn't deal with higher order bits - so for instance 73 (which is 64+9) doesn't work
73 xor 9 = 64 and
73 xor 11 = 66
so this expression tests whether the last 4 bits are 1001, and ignores the other bits, but I am having to subtract whatever the value of the first 4 bits represents.
MsgBox (((mynumber - (mynumber And 240)) Xor 9) = 0)
I can't see a simpler bitwise trick to ignore bits 1 to 4.
yes, I can now.
msgbox ((mynumber and 15) = 9)
(edit - and now I also see that
@The_Doc_Man and
@Galaxiom also mentioned this solution)