int Sqrt(int x)
{
unsigned int k = x;
unsigned int add = (1 << ((sizeof(x)*8 - 1 ) / 2));
int result = 0;
while(add > 0)
{
result |= add;
if (k < result*result)
result -= add;
add >>= 1;
}
return result;
}
#include <stdio.h>
int main(int argc, char** argv)
{
printf("%d\n", Sqrt(4));
printf("%d\n", Sqrt((1<<15)*(1<<15)));
return 0;
}