登 录
所用单片机:EM78系列,所用仿真器ICE468。
int 1byte , long 4byte
Bit data type cannot be used as a return value.
Double and float are NOT supported by the EM78 Series C Compiler.
开平方根
unsigned long sqrt_16(unsigned long M) { unsigned long N; int i; unsigned long tmp, ttp; // 结果、循环计数 if (M == 0) // 被开方数,开方结果也为0 return 0; N = 0; tmp = (M >> 30); // 获取最高位:B[m-1] M <<= 2; if (tmp > 1) // 最高位为1 { N ++; // 结果当前位为1,否则为默认的0 tmp -= N; } for (i=15; i>0; i--) // 求剩余的15位 { N <<= 1; // 左移一位 tmp <<= 2; tmp += (M >> 30); // 假设 ttp = N; ttp = (ttp<<1)+1; M <<= 2; if (tmp >= ttp) // 假设成立 { tmp -= ttp; N ++; } } return N; }
抱歉!评论已关闭.