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

后端 未结 30 3856
故里飘歌
故里飘歌 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 05:59

    Bit shifts are fast. They were implemented in CPU instruction sets long before division and modulus operations were. Many of us have used bit shifts for arithmetic that is simple on pencil and paper, but not available on our CPUs.

    For example:

    • I've used bit shifts for projects involving factoring large composites into their prime factors.
    • I have also used bit shifts for finding the square and cube root of arbitrarily large integers.

提交回复
热议问题