How to turn off some bits while ignoring others using only bitwise operators

前端 未结 2 554
感动是毒
感动是毒 2021-02-04 02:55

I\'ve searched for this, but my results were unsatisfactory, probably because of how hard it is to word. I have one object, state, which is a byte that

2条回答
  •  深忆病人
    2021-02-04 03:10

    If you just invert the bits of the parts, you can just AND it with the state

     void disableParts(byte parts) {
         byte invertOfParts = 0b11111111 - parts;
         state &= invertOfParts
     }
    

提交回复
热议问题