or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Do you want to remove this version name and description?
Syncing
xxxxxxxxxx
2024 Homework4 (quiz3+4)
contributed by <
williamlin0518
>第三週測驗題
測驗 1
i_sqrt
為找出平方根的函式,用於計算整數 x 的平方根,假設 x 總是正值。這個函數使用了一種名為"二分搜尋法"的算法來計算平方根。使用一個 for 迴圈遍歷 31 個位元,從最高有效位元開始。
使用 ffs / fls 取代 __builtin_clz
分支/無分支實作
平方根運算的程式碼
測驗 2
Bitwise Operations for Division and Modulo by 10
Goal
Bitwise Operations
range :
0~19
make sure 1.90<19/x<1.99 ( Accurate to the first decimal point )using
N = 7
and13
( \(\dfrac{13}{2^7}\) = \(0.1015625\) ) to close1/10
\(tmp\times \dfrac{13}{2^7}\) = \(tmp\times 13/8 \times 8 \div 128\)
question
題目包裝程式碼:
question 1 :
uint32_t x = (in | 1) - (in >> 2);
, whyin
need to be odd number?uint32_t q = (x >> 4) + x;
\(q=\dfrac{3}{4}in\div 16+\dfrac{3}{4}in=\dfrac{51}{64}in=0.796875in\)\(0.796875\approx\dfrac{8}{10}\) so
CCCC
is 3((q & ~0x7) + (*div << DDDD))
should equal10*div
,*div * 8 = (q >> 3) << 8 = q & ~0x7 ;
soDDDD
is 1撰寫不依賴任何除法指令的 % 9 (modulo 9) 和 % 5 (modulo 5) 程式碼
Modulus without Division, a tutorial