How to divide integer by a constant integer with right shift operators? [duplicate]

一个人想着一个人 提交于 2019-12-12 03:03:08

问题


I'm interested how to do this, because I just found out you can do integer multiplication easily, by using left shift operators:

x * 25 = (x << 4) + (x << 3) + x

Where the sum of base 2 powers equals to 25: 2^4+2^3+2^0 = 25

How does x / 25 work out with right shifts?

Edit: I'm not going to replace division and multiplication in my programs by these shift operators in hope of speed boost ;)

来源:https://stackoverflow.com/questions/16088086/how-to-divide-integer-by-a-constant-integer-with-right-shift-operators

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!