Home > C# Snippets, Development > Converting HEX Byte String to Byte

Converting HEX Byte String to Byte

If you have a Byte that is actually stored in an ASCII string for instance "5E" and are wanting this to be converted to 0x5E you can perform one simple command.

using System

public byte HexStringToByte(string hexByte)
{
    return Byte.Parse(hexByte, NumberStyles.HexNumber);
}

There is a restriction with this however, there must be only one byte in the string. This could be extended quite easily to have a byte string of multiple hex bytes and return an array or list of bytes.

  1. No comments yet.
  1. No trackbacks yet.
*

%d bloggers like this: