Reading bytes and converting to int

cal callumenator at gmail.com
Sat Aug 25 12:44:32 PDT 2012


On Saturday, 25 August 2012 at 15:23:45 UTC, joao wrote:
> Hello everyone, I recently discovered the D language.
> So, I want to open a file a read 4 bytes and get the int value.
>
> string bytes = f.read(4)
>
> I tried to cast but give me message it was deprecated.
>
> uint value = cast (uint) bytes
>
> If bytes was for example, "\x24\x00\x00\x00" I would like to 
> value to be 0x24.
> I know how to do this in Python, it is done with struct.unpack.
> Thanks.

auto i = cast(ubyte[])std.file.read("filename");
int val = std.bitmanip.read!(int, 
std.system.Endian.littleEndian)(i)




More information about the Digitalmars-d-learn mailing list