hexBytes

The hexBytes function is similar to the hexString one except that it returns the hexadecimal data as an array of integral.

  1. auto hexBytes()
    @property @trusted nothrow pure
    hexBytes
    (
    string hexData
    T = ubyte
    )
    (
    )
    if (
    hexData.isHexLiteral &&
    isIntegral!T
    &&
    (T.sizeof <= 4)
    )
  2. auto hexBytes(string hexData)

Parameters

hexData

the string to be converted.

T

the integer type of an array element. By default it is set to ubyte but all the integer types, excepted ulong and long, are accepted.

Return Value

Type: auto

an array of T.

Examples

1 // conversion at compile time
2 auto array1 = hexBytes!"304A314B";
3 assert(array1 == [0x30, 0x4A, 0x31, 0x4B]);
4 // conversion at run time
5 auto arbitraryData = "30 4A 31 4B";
6 auto array2 = hexBytes(arbitraryData);
7 assert(array2 == [0x30, 0x4A, 0x31, 0x4B]);

Meta