The ^ binary XOR operator is sometimes mistaken for a power operator, but e.g. 2 ^ 2 evaluates to 0, not 4.

Consider expressing powers of 2 using a bit shift instead.