Sunday, December 30, 2018

Calculating the square root of 8-bit binary number - Electrical Engineering Stack Exchange


ny help, but there's an ingeniously simple way to calculate a square root:

unsigned char sqrt(unsigned char num)  {      unsigned char op  = num;      unsigned char res = 0;      unsigned char one = 0x40;        while (one > op)          one >>= 2;        while (one != 0)      {          if (op >= res + one)          {              op -= res + one;              res = (res >> 1) + one;          }          else          {              res >>= 1;          }            one >>= 2;      }      return res;  }  

I don't know much about what can and can't be done in sequential logic, but since this algorithm finishes in just 4 loops, you might be able to implement it in 4 stages.

No comments:

Post a Comment