Bit shift 位移位平方根

Bit shift 位移位平方根,bit-shift,square-root,Bit Shift,Square Root,我正在研究通过位移位的快速平方根算法。我被维基百科的代码卡住了 short isqrt(short num) { short res = 0; short bit = 1 << 14; // The second-to-top bit is set: 1L<<30 for long // "bit" starts at the highest power of four <= the argument. while (bit >

我正在研究通过位移位的快速平方根算法。我被维基百科的代码卡住了

short isqrt(short num) {
    short res = 0;
    short bit = 1 << 14; // The second-to-top bit is set: 1L<<30 for long

    // "bit" starts at the highest power of four <= the argument.
    while (bit > num)
        bit >>= 2;

    while (bit != 0) {
        if (num >= res + bit) {
            num -= res + bit;
            res = (res >> 1) + bit;
        }
        else
            res >>= 1;
        bit >>= 2;
    }
    return res;
}
short isqrt(short num){
短res=0;
短位=1=分辨率+位){
num-=res+位;
res=(res>>1)+位;
}
其他的
res>>=1;
位>>=2;
}
返回res;
}
我知道它可以产生正确的结果,但它是如何产生的呢?我对这句话特别困惑,, res=(res>>1)+位; 为什么res在这里要除以2?
有人能解释一下吗?谢谢!

>1
是按位右移,例如“除以2”<代码>>>2将被4除,而
>n
是“被2除**(n)”你能解释一下为什么res在这里被2除吗?在这里你可以找到你问题的解释这是否回答了你的问题?