using System; using System.Collections.Generic; using System.Text; namespace WIDESEA_Common.Tools { public class DataTrans { /// /// 字节转bit字符串(注意偏移量0,对应的是下标7) /// /// 字节 /// public static char[] Byte2Bit(byte b) { string strTemp = Convert.ToString(b, 2).PadLeft(8, '0'); return strTemp.ToCharArray(); } /// /// 获取字符串 /// /// 源 /// 起始位置 /// public static string GetStr(byte[] socure, int start) { //前两位是西门标识位 //var len = (short)socure[start + 1]; int len = 15; if (socure.Length < 15) { len = socure.Length; } List newByte = new List(); for (int i = 0; i < 15; i++) { newByte.Add(socure[start + i + 2]); } return Encoding.ASCII.GetString(newByte.ToArray()).Replace("\0", ""); } } }