using System;
|
using System.Collections.Generic;
|
using System.Text;
|
|
namespace WIDESEA_Common.Tools
|
{
|
public class DataTrans
|
{
|
/// <summary>
|
/// 字节转bit字符串(注意偏移量0,对应的是下标7)
|
/// </summary>
|
/// <param name="b">字节</param>
|
/// <returns></returns>
|
public static char[] Byte2Bit(byte b)
|
{
|
string strTemp = Convert.ToString(b, 2).PadLeft(8, '0');
|
return strTemp.ToCharArray();
|
}
|
|
/// <summary>
|
/// 获取字符串
|
/// </summary>
|
/// <param name="socure">源</param>
|
/// <param name="start">起始位置</param>
|
/// <returns></returns>
|
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<byte> newByte = new List<byte>();
|
for (int i = 0; i < 15; i++)
|
{
|
newByte.Add(socure[start + i + 2]);
|
}
|
return Encoding.ASCII.GetString(newByte.ToArray()).Replace("\0", "");
|
}
|
}
|
}
|