24 lines
587 B
D
24 lines
587 B
D
private import std.bitmanip : nativeToLittleEndian, littleEndianToNative;
|
|
|
|
alias littleEndianInv = nativeToLittleEndian;
|
|
|
|
uint littleEndian(in ubyte[] input) @safe pure nothrow @nogc
|
|
in
|
|
{
|
|
assert(input.length == uint.sizeof);
|
|
}
|
|
body
|
|
{
|
|
ubyte[uint.sizeof] buf = input;
|
|
return littleEndianToNative!uint(buf);
|
|
}
|
|
|
|
unittest
|
|
{
|
|
ubyte[] test0 = [0, 0, 0, 0];
|
|
ubyte[] test1 = [86, 75, 30, 9];
|
|
ubyte[] test2 = [255, 255, 255, 250];
|
|
assert(littleEndian(test0) == 0x00000000);
|
|
assert(littleEndian(test1) == 0x091e4b56);
|
|
assert(littleEndian(test2) == 0xfaffffff);
|
|
}
|