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.
Syncing
xxxxxxxxxx
2018q1 Homework2 (assessment)
contributed by <
catpig1630
>第一題
第 1 週測驗題測驗
3
在 C 程式中,表達式
1 << 2 + 3 << 4
求值後為何?(a)
512(b)
16(c)
26(d)
52(e)
25解法
+的優先權大於 << 因此
= 1 << 5 << 4
= 32 << 4
= 512
延伸問題
這是我找到的C語言運算子優先權,我認為優先權的意義應該是用讓大家有個規範可以遵守,增加code的易讀性,就像數學四則運算規定先乘除後加減一樣,讓每條式子的答案唯一,讓每個人對於同樣的式子有一樣的認知。
這不是第一手材料,回去翻閱 C99/C11 規格書!
- 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 →第二題
第 1 週測驗題測驗
5
考慮以下整數乘法的實作程式碼:
上述
OP
對應到下方哪個程式敘述呢?(a)
ret = n << c;(b)
ret += n;(c)
ret <<= n;(d)
ret = c << n;(e)
ret += n << c;解法
研究 for 迴圈後可看出 for 迴圈是拿來把 m 變二進位,若在那一位為1 (用 if 判斷是否為1) ,就把 n 乘上那位數,並馬上加到答案裡,像是 6 * 7 = 6 * 111(二進位) = 6 * 1 + 6 * 2 + 6 * 4 因此答案就是
(e)
ret += n << c;延伸問題
因為這個乘法的乘數是正數,若乘數為負數,m % 2 等於 0 or -1 ,則永遠進不了 if ,答案都會為 0 因此這個乘法只有在乘數為正數時才可運作。
如何修正?不要只有「因為…所以…」這樣的描述,要有推論和改進方案!我們做的是工程訓練,不是考公職。
- 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 →第三題
第 2 週測驗題測驗
3
考慮到某些實數的二進位表示形式如同 \(0.yyyyy...\) 這樣的無限循環小數,其中 \(y\) 是個 \(k\) 位的二進位序列,例如 \(\frac{1}{3}\) 的二進位表示為 \(0.01010101...\) (y =
01
),而 \(\frac{1}{5}\) 的二進位表示為 \(0.001100110011...\) (y =0011
),考慮到以下 y 值,求出對應的十進位分數值。010011
=> \(\frac{19}{X1}\)101
=> \(\frac{5}{X2}\)0110
=> \(\frac{2}{X3}\)X1 = ?
X2 = ?
X3 = ?
解法
第一小題
設 n = 0.010011…(2進位) ,左右同乘 64 , 64n = 10011.010011…(2進位) ,兩式相減等於 63n = 10011(2進位),則 63n = 19 ,因此 X1 = 63 。
第二小題
設 n = 0.101…(2進位) ,左右同乘 8 , 8n = 101.101…(2進位) ,兩式相減等於 7n = 101(2進位),則 7n = 5 ,因此 X1 = 7 。
第三小題
設 n = 0.0110…(2進位) ,左右同乘 16 , 16n = 110.0110… ,兩式相減等於 15n = 110(2進位),則 15n = 6 , n = 6/15 = 2/5 ,則 X3 = 5 。