private void buttonInsertZero_Click(object sender, EventArgs e) { string gap; if (checkBoxGap.Checked) { gap = " "; } else { gap = ""; } byte[] data = getInputBytes(); if (data == null) { return; } BitArray new_bits = Assist.HdlcInsertZeroEncode(data); byte[] new_data = Assist.BitsLsbToBytes(new_bits); textBoxInput.Text = Assist.BytesToBitsLsbString(new_data, gap); currentCode = CODE_BIT; currentBitOrder = BIT_LSB_FIRST; radioButtonBitLsb.Checked = true;//注意这里引起bit显示触发 radioButtonBit.Checked = true; }
byte[] getBytes(string str) { Byte[] data; if (str.Length > 0) { switch (currentCode) { case CODE_BIT: { foreach (char c in str) { if (c != '1' && c != '0' && c != ' ' && c != '\r' && c != '\n') { return(null); } } if (currentBitOrder == BIT_LSB_FIRST) { data = Assist.BitsLsbToBytes(str); } else { data = Assist.BitsMsbToBytes(str); } } break; case CODE_HEX: { foreach (char c in str) { if ((c < '0' || c > '9') && (c < 'a' || c > 'f') && (c < 'A' || c > 'F') && c != ' ' && c != '\r' && c != '\n') { return(null); } } data = Assist.HexToBytes(str); } break; case CODE_ASCII: default: data = System.Text.Encoding.ASCII.GetBytes(textBoxInput.Text.Trim()); break; } return(data); } return(null); }