Practical applications of bit shifting

前端 未结 4 548
-上瘾入骨i
-上瘾入骨i 2021-01-03 05:33

I totally understand how to shift bits. I\'ve worked through numerous examples on paper and in code and don\'t need any help there.

I\'m trying to come up

4条回答
  •  情歌与酒
    2021-01-03 05:51

    The most common example of bitwise shift usage I know is for setting and clearing bits.

    uint8_t bla = INIT_VALUE;
    
    bla |= (1U << N);   // Set N-th bit
    bla &= ~(1U << N);  // Clear N-th bit
    

提交回复
热议问题