I'm a bit confused after reading about how to use bitmasks to store boolean values. I would like to have a set of boolean values and then generate a unique integer for each combination of the values. Here is the current system so far:
var a = 1 << 1
var b = 1 << 2
var c = 1 << 3
var d = 1 << 4
var uniqueint1 = getInt(true, false, false)
var uniqueint2 = getInt(true, true, false)
var uniqueint3 = getInt(true, true, true)
// ...
function getInt(x, y, z) {
var value = a
if (x) value = value | b
if (y) value = value | c
if (z) value = value | d
return value
}
But the problem is, I am not sure if I am supposed to handle the "not" case, along the lines of this:
function getInt(x, y, z) {
var value = a
if (x) value = value | b
else value = value ^ b
if (y) value = value | c
else value = value ^ c
if (z) value = value | d
else value = value ^ z
return value
}
All I know is that I've seen |, &, and ^ related to bitmasks, and I know to find if a boolean is in the bitmask you do var yes = value & b, but I'm just confused how to generate the bitmask so that it handles both the if (true) and if (false) cases. Not sure if I'm supposed to be using ^ somewhere, or what else I'm doing wrong. Please advise. Thank you!