Is (n & m) <= m always true?

bit-manipulation, c, c++

Solution

Yes, it is true.

It should be readily apparent that a necessary condition for `y > x` is that at least one bit position is set to `1` in `y` but `0` in `x`. As `&` cannot set a bit to `1` if the corresponding operand bits were not already `1`, the result cannot be larger than the operands.

Problem

Given `n` and `m` unsigned integral types, will the expression ``` (n & m) <= m ``` always be true ?

Original source

Related problems