bitCast

Takes the raw bits of a value and reinterprets them as a different type.

pragma(inline, true) ref
T
bitCast
(
T
S
)
(
ref S value
)
if (
T.sizeof <= S.sizeof
)

Parameters

T

the new type.

value S

the value to reinterpret.

Return Value

Type: T

a reference to the reinterpreted value.

Examples

uint n = 0xDEADBEEF;

version (LittleEndian)
    assert(n.bitCast!(ubyte[4]) == [0xEF, 0xBE, 0xAD, 0xDE]);
version (BigEndian)
    assert(n.bitCast!(ubyte[4]) == [0xDE, 0xAD, 0xBE, 0xEF]);

Meta