toBytes

Converts the given integral value to its byte encoding

ubyte[]
toBytes
(
T
)
if (
__traits(isIntegral, T)
)

Parameters

integral T

the integral value

Return Value

Type: ubyte[]

a ubyte[] of the value

Examples

Tests the toBytes!(T)(T) function

version(LittleEndian)
{
    ulong value = 1;
    ubyte[] bytes = toBytes(value);

    assert(bytes == [1, 0, 0, 0, 0, 0, 0, 0]);
}
else version(BigEndian)
{
    ulong value = 1;
    ubyte[] bytes = toBytes(value);

    assert(bytes == [0, 0, 0, 0, 0, 0, 0, 1]);
}

Meta