Re: Reading bytes and converting to int

2012-08-26 Thread Tommi
On Sunday, 26 August 2012 at 15:18:27 UTC, Timon Gehr wrote: auto refToBigValue = (&g_bigValue)[0..1]; Thanks. Oughta read the f***ing manual instead of glancing through it: http://dlang.org/arrays.html

Re: Reading bytes and converting to int

2012-08-26 Thread Timon Gehr
On 08/26/2012 04:19 PM, Tommi wrote: On Saturday, 25 August 2012 at 20:58:47 UTC, Jonathan M Davis wrote: auto buf = file.rawRead(new ubyte[](4)); Could we somehow skip making the temporary buffer, and read from the file directly into an existing variable. Can we make a slice of one element th

Re: Reading bytes and converting to int

2012-08-26 Thread Tommi
On Saturday, 25 August 2012 at 20:58:47 UTC, Jonathan M Davis wrote: auto buf = file.rawRead(new ubyte[](4)); Could we somehow skip making the temporary buffer, and read from the file directly into an existing variable. Can we make a slice of one element that points to an existing value. im

Re: Reading bytes and converting to int

2012-08-25 Thread Jonathan M Davis
On Sunday, August 26, 2012 01:25:04 joao wrote: > It worked! Thanks. > Just one more question, I and to do the reverse. Like 4132 => > "\x24\x10" Use std.bitmanip.write: http://dlang.org/phobos/std_bitmanip.html#write - Jonathan M Davis

Re: Reading bytes and converting to int

2012-08-25 Thread joao
On Saturday, 25 August 2012 at 20:58:47 UTC, Jonathan M Davis wrote: On Saturday, August 25, 2012 22:49:18 joao wrote: Ok, so I tried both ways and gave errors: import std.stdio, std.cstream, std.system, std.bitmanip; File f = File("filename"); auto buf = f.rawRead(new ubyte[4]); auto i = peek!

Re: Reading bytes and converting to int

2012-08-25 Thread Jonathan M Davis
On Saturday, August 25, 2012 22:49:18 joao wrote: > Ok, so I tried both ways and gave errors: > import std.stdio, std.cstream, std.system, std.bitmanip; > > File f = File("filename"); > auto buf = f.rawRead(new ubyte[4]); > auto i = peek!(uint, Endian.littleEndian)(buf); > > std.stdio.File confli

Re: Reading bytes and converting to int

2012-08-25 Thread joao
On Saturday, 25 August 2012 at 20:31:22 UTC, Jonathan M Davis wrote: On Saturday, August 25, 2012 22:18:50 joao wrote: It's not hard, sorry, it's because I'm a begginner. So, all I wanted to do was to open a file and read the first 4 bytes and then return the int value. The last part I managed t

Re: Reading bytes and converting to int

2012-08-25 Thread David
Am 25.08.2012 22:18, schrieb joao: On Saturday, 25 August 2012 at 20:03:38 UTC, Jonathan M Davis wrote: On Saturday, August 25, 2012 21:50:58 joao wrote: Thanks everyone, I solved the problem. I didn't understand these bitmanip methods so I searched and found a function to do what I wanted: st

Re: Reading bytes and converting to int

2012-08-25 Thread Jonathan M Davis
On Saturday, August 25, 2012 22:18:50 joao wrote: > It's not hard, sorry, it's because I'm a begginner. > So, all I wanted to do was to open a file and read the first 4 > bytes and then return the int value. The last part I managed to > do. > But the first I'm trying. > > In Python it is something

Re: Reading bytes and converting to int

2012-08-25 Thread joao
On Saturday, 25 August 2012 at 20:03:38 UTC, Jonathan M Davis wrote: On Saturday, August 25, 2012 21:50:58 joao wrote: Thanks everyone, I solved the problem. I didn't understand these bitmanip methods so I searched and found a function to do what I wanted: string b = "\x24\x10\x00\x00"; uint i

Re: Reading bytes and converting to int

2012-08-25 Thread Jonathan M Davis
On Saturday, August 25, 2012 21:50:58 joao wrote: > Thanks everyone, I solved the problem. > I didn't understand these bitmanip methods so I searched and > found a function to do what I wanted: > > string b = "\x24\x10\x00\x00"; > uint i = byteToInt(b); > uint byteToInt(string b) { >return

Re: Reading bytes and converting to int

2012-08-25 Thread joao
Thanks everyone, I solved the problem. I didn't understand these bitmanip methods so I searched and found a function to do what I wanted: string b = "\x24\x10\x00\x00"; uint i = byteToInt(b); uint byteToInt(string b) { return b[0] | b[1] << 8 | b[2] << 16 | b[3] << 24; } => 4132

Re: Reading bytes and converting to int

2012-08-25 Thread cal
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 byte

Re: Reading bytes and converting to int

2012-08-25 Thread David
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, "\x

Re: Reading bytes and converting to int

2012-08-25 Thread nazriel
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 byte

Reading bytes and converting to int

2012-08-25 Thread 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 val