I've not done much work on using variables for bit flags so I wanted to check that this is correct before putting it into my code.
Lets say if I want to change the very last 4 bits on a string ONLY and keep the rest of the variable the same would this work?
1 2 3 4 5
//taken from wikipedia so I don't really trust it
char var = 10011001; //Okay I know this isn't right but lets just imagine it's all in bits please
char newBit = 00000110;
char flag = 00001111;
var |= (flag & newBit);
So hopefully "var" will now equal 10010110 correct?
The (flag & newBit) should equate to 00000110
Which I'm confident with but I need to know if the |= assignment leaves the first 4 bits alone sets the last four to 0110 no matter what there previous state.
These are collision states, the left 2 bits represent how the collisions should be calculated, the right 2 bits is simply whether to even start calculating collision (on, off, or this object can collide with scenes but not other objects (C_EX))
Lets say that halfway through the game I want to change C_ON to C_OFF for some reason.
I wanna call a function like updateCollide(C_OFF) and from there I'll swap the last 2 bits from 10 to 01
So if I had an object with collision state 1110 it would change to 1101