Divide a number by 5 without using division operator

Possible Duplicate:
implement division with bit wise operator
Divide a number by 3 without using *, /, +, -, % operators

I came across this question in an interview. I want to know if there any possibly way to divide a number by 5 without using division operator and if any possible solution exists using bitwise operators only.I figured one out using repeated subtraction till zero approaches. Number can be signed and unsigned. Please suggest any way out without using +,-,/,* and %.


我的第一个想法是乘以0.2(但我不知道如何使用从头开始使用按位运算符的解决方案)。


简单地减少分数,减去另一个数字直到达到零:D

int number = 25;
int divisor = 5;
int result = 0;
while((number-divisor)>=0){
  result++;
  number = number - divisor;
}

I seem to have found a way out from this link which seems to provide a answer to my question. http://codegambler.wordpress.com/2009/08/11/division-operation-without-using-division-operator/

链接地址: http://www.djcxy.com/p/37200.html

上一篇: 将数字乘以3.5而不使用*,/,%运算符

下一篇: 不使用除法运算符将数字除以5