15.09.2018, 18:50
Hi, I need help with bit operations..
Lets say I have all bits "turned on"
Now I have variables ex.
And I must turn off 8th bit and get something like
I tried
Lets say I have all bits "turned on"
Код:
11111111111111111111111111111111
Код:
new myVar = 8;
Код:
11111110111111111111111111111111
Код:
new data; // all bits off new myVar1 = 2, myVar2 = 8, myVar3 = 12; data |= myVar1; // turn on 2nd bit data |= myVar1; // turn on 12th bit print((data & myVar1) ? ("myVar1 passed") : ("myVar1 failed")); print((data & myVar2) ? ("myVar2 passed") : ("myVar2 failed")); print((data & myVar3) ? ("myVar3 passed") : ("myVar3 failed")); // Out: [20:49:25] myVar1 passed [20:49:25] myVar2 failed [20:49:25] myVar3 failed