Set individual bit in C++

前端 未结 6 812
深忆病人
深忆病人 2021-01-13 13:33

I have a 5 byte data element and I need some help in figuring out how in C++ to set an individual bit of one of these byte; Please see my sample code below:



        
6条回答
  •  遥遥无期
    2021-01-13 14:15

    m_TxBuf[1] |= 4;
    

    To set a bit, you use bitwise or. The above uses compound assignment, which means the left side is one of the inputs and the output.

提交回复
热议问题