math: improve how bitwise ANDs are handled