Why is squaring a number faster than multiplying two random numbers?

前端 未结 14 2380
终归单人心
终归单人心 2021-01-30 07:18

Multiplying two binary numbers takes n^2 time, yet squaring a number can be done more efficiently somehow. (with n being the number of bits) How could that be?

Or is i

14条回答
  •  渐次进展
    2021-01-30 07:50

    I have it!

    2 * 2
    

    is more expensive than

    2 << 1
    

    (The caveat being it only works for one case.)

提交回复
热议问题