/// <summary>
/// ushort[]转string
/// </summary>
/// <param name="inUshort">ushort数组</param>
/// <returns>string字符串</returns>
public static string UShortConvertToString(ushort[] inUshort)
{
byte[] outByte = new byte[inUshort.Length * 2];
string code = string.Empty;
for (int i = 0; i < inUshort.Length; i++)
{
byte[] bufByte = BitConverter.GetBytes(inUshort[i]);
outByte[i * 2] = bufByte[0];
outByte[(i * 2) + 1] = bufByte[1];
}
code = System.Text.Encoding.ASCII.GetString(outByte);
return code.Replace("\0", string.Empty).Trim();
}
/// <summary>
/// string 转偶数 byte数组
/// </summary>
/// <param name="code">条码</param>
/// <returns>byte数组</returns>
public static byte[] StringConvertToUShort(string code)
{
byte[] byteCode = new byte[100];
int length = Encoding.ASCII.GetBytes(code).Length;
for (int i = 0; i < length; i++)
{
byteCode[i] = Encoding.ASCII.GetBytes(code)[i];
}
return byteCode;
}