I was going through the TBitReader and found this optimization for more compliant masks.
Technically, this shouldn't even be a problem in the code but I want to use the best mask calculation algorithm as an example for others. The problem was collision left shifting 1 by the total number of bits is that the shift would push the bit off.
Instead of (1<<$bits) - 1 it should be ~(-1 << $bits) as this preserves the masking when $bits = PHP_INT_SIZE * 8
I was going through the TBitReader and found this optimization for more compliant masks.
Technically, this shouldn't even be a problem in the code but I want to use the best mask calculation algorithm as an example for others. The problem was collision left shifting 1 by the total number of bits is that the shift would push the bit off.
Instead of
(1<<$bits) - 1
it should be~(-1 << $bits)
as this preserves the masking when $bits = PHP_INT_SIZE * 8