# 2017q3 Homework1 (clz) contributed by <`BreezeDa`> ## Count leading Zero 顧名思義,便是計算從 MSB 開始往 LSB 算起直到碰到非 0 的 bit 為止共有幾個為 0 的 bit 以下 code 可以利用 31 - clz 而得到 $log_2(N)$ 的整數部分 ```clike= BITS = 31; for (; i < 32; --BITS) { if (N & 0x80000000) break; N <<= 1; } ``` 最後 BITS 的結果便是 $log_2(N)$ 參考資料 - [重新理解數值](https://hackmd.io/s/BkRKhQGae#count-leading-zero) - [wikipedia : clz](https://en.wikipedia.org/wiki/Find_first_set#CLZ)
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up