# 第一題 ## 題目說明 1. 左上App標題名稱為『10進位數字系統轉2進位數字系統』 2. 第一個按鈕(Button)標題『按下進行數字內容清除』如圖一所示,按下後可將【文字方塊一】(TextBox)、【文字方塊二】內之內容清除,以供新的十進位數字輸入進行轉換。 3. 第二個按鈕標題『按下進行數字系統轉換』如圖一所示,按下後可將使用者於【文字方塊一】,十進位數字輸入文字方塊內之數字進行轉換成二進位數字,並於【文字方塊二】,二進位數字輸出文字方塊呈現。 4. 分別在兩個文字方塊上方置放兩個標籤(Label)作為提示字串。  ## 介面  拉取textbox兩個,label兩個,button兩個,form重命名為10進位數字系統轉2進位數字系統,並依照題目重命名按鈕和label ## 程式碼 ### button1_Click ```csharp private void button1_Click(object sender, EventArgs e) { textBox1.Text = ""; textBox2.Text = ""; } ``` 清空的按鈕將textBox1和textBox2的文字清空(設為"") ### button2_Click ```csharp private void button2_Click(object sender, EventArgs e) { textBox2.Text =Convert.ToString(Convert.ToInt32(textBox1.Text), 2); } ``` 將textBox2的文字輸出為二進位的結果 #### 解析轉換代碼 ```csharp Convert.ToString(Convert.ToInt32(textBox1.Text), 2) ``` ##### textBox1.Text 輸入的數字 ##### Convert.ToInt32 將屬於String的textBox1轉換成int ```csharp Convert.ToInt32(textBox1.Text) ``` ##### Convert.ToString(,2) 轉換數字成二進位 ```csharp Convert.ToString(Convert.ToInt32(textBox1.Text), 2) ```
×
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