StringUtils HexToBinary Method C# API
Returns a byte array containing the values of a sequence of hexadecimal numbers in the hex string parameter.

Namespace: Facilita.Util
Assembly: fc_clr (in fc_clr.dll) Version: 9.5.7.98
Syntax

public static byte[] HexToBinary(
	string hex
)

Parameters

hex
Type: System String
The input string, composed of pairs of hexadecimal characters where each pair represents a single byte.

Return Value

The binary values of the hexadecimal bytes in the input string.
Remarks

This method is used to convert a string containing the hexadecimal representation of a sequence of bytes into a byte array containing the binary values.

The input string must contain pairs of hexadecimal characters; white space or any non hexadecimal character between each pair is ignored.

If the second character of an expected pair of hexadecimal characters is not a valid hex character, the conversion is terminated.

Valid input format examples
"8014833031F300AB15974D4252204157"
"80 14 83 f3 31 F3 00 ab 15 97 4d 42 ef 20 41 57"
"x80 x14 xAA x30"
"80 1483xAAx31 \\x33 0080bcef4d4252204157"
Examples

The following example demonstrates converting a hex string to a byte array and back again.
string EBCDIC = "C2C9C8C4F0F1F8F04040F0F240404040404040404040E2D";
byte[] hex = StringUtils.HexToBinary(EBCDIC);
WriteMessage(StringUtils.HexToString(hex)); //  display contents
See Also