Which is better option to use for dividing an integer number by 2?

前端 未结 23 1771
甜味超标
甜味超标 2020-11-27 09:10

Which of the following techniques is the best option for dividing an integer by 2 and why?

Technique 1:

x = x >> 1;

Technique

23条回答
  •  猫巷女王i
    2020-11-27 09:40

    Just an added note -

    x *= 0.5 will often be faster in some VM-based languages -- notably actionscript, as the variable won't have to be checked for divide by 0.

提交回复
热议问题