0
我在做一個程序,我有一個ASCII代碼轉換成二進制文件,然後將其傳遞到一個數組中,喜歡保存二進制數組內
int[] c = { 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1 };
現在我已經寫程序ASCII轉換成二進制
使用下面的代碼
private void button1_Click(object sender, EventArgs e) {
string str1;
str1 = textBox1.Text.ToString();
ASCIIEncoding ascii = new ASCIIEncoding();
byte[] bytes = ascii.GetBytes(str1);
string result ="";
foreach (byte b in bytes)
result += Convert.ToString(b, 2);
//MessageBox.Show(result);
string str2;
str2 = result.ToString();
textBox2.Text = str2;
}
現在假設我給出了值「A」它被轉化爲1100001
,我想將其轉換成值1,1,0,0,0,0,1
,並將其傳遞到上述int[] c;
。
有沒有其他方法可以做到這一點?
我使用BitArray作爲由你推薦。 – 2012-03-27 07:41:16
你能否提供更清晰的使用方法?我得到錯誤作爲無效的cating錯誤 – 2012-03-27 07:51:54