When I searching about Snapping grid function. Actually it is Tile Collide.(You maybe know I learning GMS2 because of tags..)
It is not important for my question.
Cut to the chase, I learned about this formula.
pos.x - (pos.x % gridwidth) <- this is number calculation.
It worked well what I want to. And I found different formula.
This formula is working for collision of obj and tiles.
(pos.x)&~(gridwidth-1) <- this is binary calculation.
And It has same work. What happen?? I can't understand how these formula are transformed..
Actually I understand '&' has same work with subtract. But I don't understand others.
for example
var f1,f2;
var pos_x = 102;
var gridwidth = 64; // It must be even power of 2.
f1 = pos_x - (pos_x % gridwidth);
f2 = (pos_x)&(~(gridwidth-1));