Read Byte Array to Integer
Ali Çehreli
acehreli at yahoo.com
Fri Nov 22 11:22:16 PST 2013
On 11/22/2013 11:10 AM, Jeroen Bollen wrote:
> How do I read a byte array into an unsigned integer using little endian
> formatting? I know about the .read inside the std.bitmanip but I can't
> fingure out how to set it to little endian.
>
> data.read!(uint, Endian.littleEndian)();
>
> This gives me a huge compile message including the error at the top
> (without the candidates)
>
> Error: template std.bitmanip.read does not match any function template
> declaration.
It looks like you need to include std.system for Endian's definition:
import std.bitmanip;
import std.system;
void main()
{
ubyte[] data = [ 1, 2, 3, 4 ];
assert(data.read!(uint, Endian.littleEndian) == 0x04030201);
}
Ali
More information about the Digitalmars-d-learn
mailing list