It's wrong. The mistaken idea is that char
is 8 bit.
It's also pointless. The presumed problem is that m
can have more bits than char
(true) so that "unnecessary" bits are masked off.
But m
is sign-extended. That means the sign bit is copied to the higher bits. Now, when we're comparing x==0
we're checking whether all bits are zero, and with x & 0xff
we're comparing if the lower 8 bits are zero. If the 8th bit of x is copied to all higher positions (by sign extension), then the two conditions are the same regardless of whether the copied bit was 0 or 1.