Explain the following C++ method

前端 未结 4 1117
日久生厌
日久生厌 2021-01-23 18:06
#define XL     33           
#define OR      113          
#define NOR     313     
#define TN     344  

int to_bits(int critn,char *mask)
{
       unsigned int x;
             


        
4条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-23 18:33

    The last two lines are bit shifting.

    mask is taking 0x80 and shifting it (x to the mod of 8) positions eg 5 >> 2 will give you 1.

    x >> 3 is as it says, dividing it by 8, its taking x and moving all the bits 3 positions to the right (so thats 1,2,4), as a result, 8 will become 1 etc. its a little like integer div, but would be faster (as the comment says, fast divide by 8)

提交回复
热议问题