C#时间戳准换成byte发送到下位机部分代码

public void TestA()
{
int time = 1658310821;

string str = time.ToString("X4");
byte[] testb = strToHexByte(str);
}
///


/// 16进制字符串转换成16进制byte数组
///

///
///
public byte[] strToHexByte(string hexString)
{
hexString = hexString.Replace(":", "");
if ((hexString.Length % 2) != 0)
hexString += " ";
byte[] returnBytes = new byte[hexString.Length / 2];
for (int i = 0; i < returnBytes.Length; i++)
returnBytes[i] = Convert.ToByte(hexString.Substring(i * 2, 2), 16);
return returnBytes;
}

posted @ 2022-07-20 10:03  搬砖的L先生  阅读(164)  评论(0)    收藏  举报