Reading bytes and converting to int

David d at dav1d.de
Sat Aug 25 12:28:39 PDT 2012


Am 25.08.2012 17:23, schrieb joao:
> 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.

I think that is what you need/want: 
http://dlang.org/phobos/std_bitmanip.html#read


More information about the Digitalmars-d-learn mailing list