Now that I think about it, while it is an interesting brain exercise, it may not be AS practical.
If you're planning to treat a variable as a bit-array anyways and will be managing it using script calls, you might as well just use an actual array...
Though I like the idea of using bit masks to check if multiple switches are ON, since it's very fast to say
0b101011To check whether bits 1, 2, 4, and 6 are ON.You could even assign it to a string so that you can identify it by name
masks["those 6 chests"] = 0b101011And then refer to "those 6 chests" by name in all of your code.But then you could do the same thing with arrays.
areSwitchesOn([1,2,4,6])masks["those 6 chests"] = [1,2,4,6]areSwitchesOn("those 6 chests")Just seems like it makes MORE SENSE to use arrays in the end.Anyways, here's what I have for the two cases
1. To check if the specified bits are ON, Zalerinian's approach works
0b1101 & 0b1001 == 0b1001The bits that you want to be ON, must be ON in order to equal your mask.2. To check if the specified bits are OFF, we can just negate the input, and then just check if they're ON.
For example, I want the first two bits to be ON
Code:
~0b1100 & 0b0011 == 0b0011
I think that should work.