Reading file as binary

Adam D. Ruppe destructionator at gmail.com
Wed May 29 15:23:31 PDT 2013


On Wednesday, 29 May 2013 at 22:03:24 UTC, baws wrote:
> With my code, im getting the integer values, If i use 
> cast(byte[]) on read and writefln("Reading header info: 0x%x", 
> bytesRead[0]);

You're reading the file correctly, just not printing it all out 
in hex.

>     writefln("Reading header info: %s", bytesRead);

this line should be printing the right data, just in decimal 
notation instead of hex. If you do the %x with one byte at a time 
you'll probably get the output you want:

         byte[] a = [10, 16, 32, 123];
         writef("0x");
         foreach(b; a)
             writef("%x", b);
         writef("\n");


More information about the Digitalmars-d-learn mailing list