Skip to content

Instantly share code, notes, and snippets.

@fpGHwd
Last active November 9, 2020 12:27
Show Gist options
  • Save fpGHwd/b197231929119203e165 to your computer and use it in GitHub Desktop.
Save fpGHwd/b197231929119203e165 to your computer and use it in GitHub Desktop.
c# string to hex byte
/// <summary>
/// 字符串转16进制字节数组
/// </summary>
/// <param name="hexString"></param>
/// <returns></returns>
private static byte[] strToToHexByte(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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment