Are 'addition' and 'bitwise or' the same in this case?

后端 未结 6 817
醉酒成梦
醉酒成梦 2020-12-16 11:45

Say I have four 32-bit numbers, defined so that their bits don\'t overlap, i.e.

unsigned long int num0 = 0xFF000000;
unsigned long int num1 = 0x00FF0000;
uns         


        
6条回答
  •  渐次进展
    2020-12-16 12:39

    Yes, as (seen bitwise) 0+1 is the same as 0|1. The only difference is 1|1 (=1) vs. 1+1(=0b10), i.e. create a 0 and having overflow, affecting the bits to the left).

    So in your case both are equivalent. But you should go to the safe side and choose the less error-prone one.

提交回复
热议问题