XiChang/DM_Weight/Common/StaticClass.cs

26 lines
748 B
C#
Raw Permalink Normal View History

2024-02-27 09:01:14 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DM_Weight.Common
{
public class StaticClass
{
public static byte[] StrToHexByte(string hexString)
{
if (string.IsNullOrEmpty(hexString))
{
return null;
}
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).Replace(" ", ""), 16);
return returnBytes;
}
}
}