Posts Tagged ‘ascii’

Converting HEX Byte String to Byte

April 5th, 2011 Comments off

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.

%d bloggers like this: