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 getter]
    @property @trusted nothrow pure
    hexBytes
    (
    string hexData
    T = ubyte
    )
    ()
    if (
    hexData.isHexLiteral &&
    isIntegral!T
    &&
    (T.sizeof <= 4)
    )
  2. auto hexBytes [@property getter]

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

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

Meta