contributed by < bclegend >
bclegend
1
版本一相較於版本二改變了函式 log2 的使用,log2(N) 函數用來計算數字 N 的以 2 為底的對數。 並將該函式改寫為以下的版本,利用 n 若是比 1 還大時進行 bitwise 操作向右移一個位元,並紀錄下位移的次數來計算原本需要使用函式 log2 來取得的數值
log2
log2(N)
N
n
while (n > 1) { n >>= 1; msb++; }
2
參考《Hacker's Delight》,採用 bitwise operation 來實作除法
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up