补一个空格(半角):
private static byte[] FormatData(String str) { var yu = str.Length % 8; if (yu == 0) return Encoding.GetEncoding(Consts.Charset).GetBytes(str); var size = 8 - yu; var arr = new byte[str.Length + size]; var data = Encoding.GetEncoding(Consts.Charset).GetBytes(str); var i = 0; for (; i < data.Length; i++) { arr[i] = data[i]; } for (var j = 0; j < size; j++,i++) { arr[i] = Convert.ToByte(' '); } return arr; } private static byte[] FormatByte(IList<byte> arr) { var i = 0; for (; i < arr.Count; i++) { if (Convert.ToChar(arr[i]) == ' ') { break; } } var result = new byte[i]; for (var j = 0; j < i; j++) { result[j] = arr[j]; } return result; }