So I understand that my question is about masking. I saw the documentation of masking for javascript here.
so I tried:
var PEN = 1;
var CHAIR = 2;
var TABLE = 4;
> PEN | CHAIR
3
But what if what I have is 3
how do I get what I have from that number alone?
Original Question
Say, I have the following constant numbers:
1 | 2 | 4
These numbers corresponds to a something.
Let us say: 1 is a pen, 2 is a chair and 4 is a table.
Possibilities:
If I have the #1 it means I have a pen but NO chair and table.
If I have the #2 it means I have a chair but NO pen and table.
If I have the #4 it means I have a table but NO pen and chair.
If I have the #3 it means I have a pen and a chair but NO table.
If I have the #6 it means I have a chair, a table but NO pen.
If I have the #7 it means I have a pen, a chair and a table.
Question: Now say all I know about is the number 6. How do I programatically decipher that 6 means 2 and 4 or I have a chair and a table?
Sorry, this is also confusing me. I'm trying to reimplement a skills list algorithm for a game to javascript. Where if I have 6 it means I have the 2nd and 3rd skill but not the 1st skill.
Also what is this approach called?