okay, I needed some more brain work see the following as a tutorial for newbies
Decimal |
Binary |
1 |
1 |
2 |
10 |
4 |
100 |
8 |
1000 |
16 |
10000 |
32 |
100000 |
64 |
1000000 |
128 |
10000000 |
So I get a number such as 5 and convert it to binary: 0101
Thus I see the flags 1 and 4!
next step... OR statement. To transfer the value. I want to add flag 8 to 5.
example: 8 OR 5 = 8|5 is 1000 | 0101 results in
1 | 0 → 1
0 | 1 → 1
0 | 0 → 0
0 | 1 → 1
and get 1101 → 2^3+2^2+2^1+2^0 = 13
getting it slowly :)
next: how to check if value is inside we use AND
example: is flag 4 inside 13?
13: 1101
4: 0100
using the logical AND statement
1 & 0 → 0
1 & 1 → 1
0 & 0 → 0
1 & 0 → 0
we get 0100 which is 2^2 = 4.
so in PHP: (4 & 13) returns 4, then flag is inside!
if you try (4 & 16) it returns 0, flag not inside.
after writing this I found the php: bitwise operators reference.