Making a particular bit "0" in C++

This question already has an answer here:

  • How do you set, clear, and toggle a single bit? 26 answers

  • Just use :

    p = p & ~(1u<<3);
    

    What happens here ?

     1. (1u<<3)       0...01000
     2. ~(1u<<3)      1...10111 // Invert the bits
     3. p & ~(1u<<3)  *****0*** // Here * means the bit representation of p
    

    That's how the bit changes to 0.
    Hope it helps :)

    链接地址: http://www.djcxy.com/p/28792.html

    上一篇: th比特为零?

    下一篇: 在C ++中创建一个特殊的位“0”