hello all,
n is an 32bit-integer, how to calculate
sqrt(n)
I know high(n) is the the value, but how to use bit operation to
implement this function.
thanks in advance.
What you need is to post in a more appropriate newsgroup
(comp.programming would be appropriate), to state your problem more
clearly, and to describe more clearly what the acceptable error is.
Judging from your further comments what you want is a fast, rough
approximation for an integer square root. One way to do this is to
find p, the position of the high order bit of n, and right shift n p/2
bits. If you know that n is large (greater than 2**16) and you are
willing to accept a really rough approximation just right shift n 16
bits (that gives you your "high") and add 1.
If you restate your request in comp.programming and state your
requirements more clearly, you should get a better answer than this.
In particular, you should characterize n more clearly than being a 32
bit integer, the level of accuracy that you desire (e.g., within a
factor of two), and whether there are storage constraints, i.e.,
whether it's okay to use lookup tables.