Read Byte Array to Integer

Jeroen Bollen jbinero at gmail.com
Fri Nov 22 11:44:54 PST 2013


On Friday, 22 November 2013 at 19:22:16 UTC, Ali Çehreli wrote:
> 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

I have std.system included... :s


More information about the Digitalmars-d-learn mailing list