当前是为了解决使用8位单片机使用除法出现报错问题。
talk is cheap…
//移位逼近法实现除法
unsigned long Division(unsigned long dividend,unsigned long divisor)
{
unsigned long resault = 0;
unsigned char i = 0;
if(divisor == 0)
{
return 0;
}
while(dividend >= divisor)
{
for(i = 0;dividend >= (divisor << i);i++);
dividend -= (divisor << (i - 1));
resault += 1 << (i - 1);
}
return resault;
}
//移位逼近法实现求余
unsigned long remainder(unsigned long dividend,unsigned long divisor)
{
unsigned char i = 0;
if(divisor == 0)
{
return 0;
}
while(dividend >= divisor)
{
for(i = 0;dividend >= (divisor << i);i++);
dividend -= (divisor << (i - 1));
}
return dividend;
}