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

后端 未结 6 805
醉酒成梦
醉酒成梦 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:15

    No:

    num3 + num3 => 0x000001FE
    
    num3 | num3 => 0x000000FF
    

    Of course, as long as you ensure that you only add things together where you know that they don't have the same bits set, you should be safe.

提交回复
热议问题