Explain the following C++ method

前端 未结 4 962
日久生厌
日久生厌 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:26

    In C++, just like most programming languages, you can only return one value. To "return" two values, it's a common C/C++ practice to return one and pass a pointer to an object and modify that object via the pointer (mask in this case).

    The object that mask point to will be assigned a bitmask with exactly one bit set. This is done be taking the hexadecimal value 0x80 (1000 0000 in binary form) and right shift it 0 to 7 steps. The exact number of steps is decided by x, which is computer using some application-specific logic.

    The value returned is the x / 8.

    You can see the routine as a division routine that returns x/8 and the remainder (like x modulo 8, but expressed as a bit mask rather than an integer value).

提交回复
热议问题