How can I multiply and divide using only bit shifting and adding?

后端 未结 14 1782
清歌不尽
清歌不尽 2020-11-22 15:09

How can I multiply and divide using only bit shifting and adding?

14条回答
  •  借酒劲吻你
    2020-11-22 15:50

    1. A left shift by 1 position is analogous to multiplying by 2. A right shift is analogous to dividing by 2.
    2. You can add in a loop to multiply. By picking the loop variable and the addition variable correctly, you can bound performance. Once you've explored that, you should use Peasant Multiplication

提交回复
热议问题