Bitmask Help

Blueprints are not really goot for bitmask, UE4 don’t use them much.

Here general how bitmasks work:

Integers need to be power of 2 to make it work. 1,2,4,8,16,32,64,128 etc. integers in blueprints are 32-bit there also Byte type which is 8-bit.

Each power of 2 number represent is specific bit, you add them up to set specifics bits to 1 and you subtract that number to set it to 0. so let say we have 8-bit integer 00000000, if you do 2+4+32+128 it will be 166 which in binary is 10100110 then let say sunstract 4 from 166, it will be 162 it will cause 3rd bit to 0, and it will be 10100010

Now how to check if specific bit is set? you use it with AND operator (which is equivalent of AND gate), which in most languages is “&” blueprint has it too

let say we want to check 4nd bit is set to which will be number 8, so you do Bitmask & 8 If it return 0 it means bit is 0 if it’s return the bit number (in this case 8) or something else it’s means it’s set to 1