Have you ever had to use bit shifting in real projects?

后端 未结 30 3854
故里飘歌
故里飘歌 2020-12-02 05:35

Have you ever had to use bit shifting in real programming projects? Most (if not all) high level languages have shift operators in them, but when would you actually need to

30条回答
  •  臣服心动
    2020-12-02 06:07

    • Creating nice flag values for the enums (rather than typing manually 1, 2, 4...)
    • Unpacking the data from the bit-fields (many network protocols use them)
    • Z-curve traversal
    • Performance hacks

    And I cannot think of many cases when they are being used. It's usually other way around - there is some specific problem, and it turns out that employing bit operations will yield the best results (usually in term of performance - time and/or space).

提交回复
热议问题