Electronic – Calculating the square root of 8-bit binary number

digital-logic

I was looking for a way to calculate the square root of a given 8-bit number using only digital combination or sequential logic. Is that possible?

One way may be to just use a look up table since I'm not considering fractional parts at all (so \$ \sqrt{10} \simeq 3\$) but there has to be a better way than this. Can someone point me to that?

Best Answer

Lookup tables have been mentioned in comments. There are two approaches.

Fast
Create a 256 bytes long table, with every next value the square root of the corresponding index. This is fast since you use the argument as index to access the right value directly. Drawback is that it needs a long table, with lots of duplicate values.

Compact
As said, an 8-bit integer can only have values 0 through 255, and the corresponding square roots are 0 through 16 (rounded). Construct a 16 entry table (zero-based) with the n-th entry the maximum value for the argument for which the square root is n. Table would look like this:

 0  
 2  
 6  
12  
20
etc.

You walk through the table and stop when you encounter a value greater than or equal to your argument. Example: square root of 18

set index to 0
value[0] = 0, is less than 18, go to the next entry  
value[1] = 2, is less than 18, go to the next entry  
value[2] = 6, is less than 18, go to the next entry  
value[3] = 12, is less than 18, go to the next entry
value[4] = 20, is greater than or equal to 18, so sqrt(18) = 4

While the fast lookup table has a fixed execution time (just one lookup), here the execution time is longer for higher value arguments.

For both methods goes that, by choosing different values for the table, you can select between a rounded or a truncated value for the square root.