@hxtang Thanks for your good idea. But I think Rule 1 is not strong enough, because the two methods in step2 meet Rule 1, but the method of using counts of bits in mask is wrong. You probably should update Rule 1 to make it more detail.
@StefanPochmann Well the thing with many of these solutions is that they are very intuitive but are tricky to prove, although I agree with you that proving them is important. I'll think of a proof and post it. Thanks for your comments :)