public string Decode(byte[] data) { var reader = new BitReader(data); while (reader.Remain > 8) { var start = reader.ReadByte(); if (start == 2) break; } var len = reader.ReadInt(16); var result = new StringBuilder(len); for (int i = 0; i < len; i++) { var b = reader.ReadInt(7); var ch = Convert.ToChar(b); result.Append(ch); } return result.ToString(); }
public string Decode(byte[] data) { var reader = new BitReader(data); while(reader.Remain > 8) { var start = reader.ReadByte(); if (start == 2) break; } var len = reader.ReadInt(16); var result = new StringBuilder(len); for (int i = 0; i < len; i++) { var index = reader.ReadInt(6); var ch = Dict.Custom[index]; result.Append(ch); } return result.ToString(); }
private void ShowBinString() { Task.Factory.StartNew(() => { if (buff == null) return; var reader = new BitReader(buff); var byteLen = reader.Length / 8; var format = "D" + byteLen.ToString().Length; var bin = new StringBuilder(); for (int i = 0; i < byteLen; i++) { bin.Append(i.ToString(format)).Append(" ").Append(reader.ReadBinString(8)).Append("\r\n"); } Dispatcher.BeginInvoke(new Action(() => { BinText.Text = bin.ToString(); })); }); }