import std.conv : text; BigEndian!ushort x; x = cast(ubyte[])[2, 0]; assert(x == 0x200); ushort tmp; x.native(tmp); assert(tmp == 512); assert(x.text == "512"); x = 1024; assert(x.raw == [4, 0]); BigEndian!float f; f = cast(ubyte[])[64, 32, 0, 0]; assert(f == 2.5); align(1) static struct Test { align(1): uint a; ushort b; ushort[2] c; } BigEndian!Test t; t = cast(ubyte[])[0, 1, 2, 3, 1, 2, 5, 6, 7, 8]; assert(t.a == 0x010203); assert(t.b == 0x0102); assert(t.c == [0x0506, 0x0708]); t = Test(42, 42, [10, 20]); assert(t.raw == [0, 0, 0, 42, 0, 42, 0, 10, 0, 20]); align(1) static struct Test2 { align(1): ubyte a; char b; ubyte[4] c; } BigEndian!Test2 t2; t2 = cast(ubyte[])[20, 30, 1, 2, 3, 4]; assert(t2.a == 20); assert(t2.b == 30); assert(t2.c == [1, 2, 3, 4]);
Represents a big endian type. Most significant bits come first, so 0x4000 is, for example, represented as [04, 00].