Q:

How to test if zeros have changed to ones (but not the other way around)

I have a binary mask which at some point I'm updating. It's ok for 1s in my old mask to become 0s but the other way around is not allowed. How can I assert using some binary operations that none of the 0s in the mask have turned into 1s? 

A:

if (~old & new)

If you also want to know which bits changed from 0 to 1, just read each bit in bits = ~old & new;. If you just want to know if any 0s became 1s, that first line of code will do.

