Using bitwise operators

后端 未结 12 1661
既然无缘
既然无缘 2021-01-06 08:21

I\'ve been studying C# and ran accross some familiar ground from my old work in C++. I never understood the reason for bitwise operators in a real application. I\'ve never u

12条回答
  •  南笙
    南笙 (楼主)
    2021-01-06 08:55

    Another typical (but I think less common) usage is to compose several numbers into one big number. An example for this can be the windows RGB macro:

    #define RGB(r, g ,b)  ((DWORD) (((BYTE) (r) | ((WORD) (g) << 8)) | (((DWORD) (BYTE) (b)) << 16)))
    

    Where you take 3 bytes and compose an integer from them the represent the RGB value.

提交回复
热议问题