Try   HackMD

2022q1 Homework4 (quiz4)

contributed by < Wallmountain >

https://hackmd.io/@sysprog/linux2022-homework4 裡頭的描述:「開發紀錄」的 HackMD 網址應該要用「固定網址」(參見 用固定網址發布筆記),也就是如 https://hackmd.io/@itsme/XXXX 的形式。

請修正登記於 https://hackmd.io/@sysprog/linux2022-homework4 裡頭的超連結。

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
jserv

測驗一

延伸第 3 週測驗題的測驗 7,已知輸入必為大於 0 的數值 (即 x > 0),以下程式碼可計算

log2(x)⌉,也就是 ceillog2 的組合並轉型為整數:

int ceil_log2(uint32_t x)
{uint32_t r, shift;

​   x--;
​   r = (x > 0xFFFF) << 4;
​   x >>= r;
​   shift = (x > 0xFF) << 3;
​   x >>= shift;
​   r |= shift;
​   shift = (x > 0xF) << 2;
​   x >>= shift;
​   r |= shift;
​   shift = (x > 0x3) << 1;
​   x >>= shift;return (r | shift | x >> 1) + 1;       
}