Re: Reading and converting binary file 2 bits at a time

2015-08-31 Thread Andrew Brown via Digitalmars-d-learn
Thanks very much for all the help, your advice worked a treat. One final question, originally I was defining the struct inside the main loop and it was using 4 bytes per field rather than 2 bits, e.g.: import std.bitmanip; import std.stdio; struct Crumb1 { mixin(bitfields!(

Re: Reading and converting binary file 2 bits at a time

2015-08-31 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 31 August 2015 at 18:00:54 UTC, Andrew Brown wrote: Is this correect behaviour? Yes, the reason is because the nested struct has a hidden member - a pointer to its stack context. This allows it to access variables from the surrounding local scope. It adds 8 bytes on 64 bit cuz

Re: Reading and converting binary file 2 bits at a time

2015-08-30 Thread Gary Willoughby via Digitalmars-d-learn
On Sunday, 30 August 2015 at 00:02:16 UTC, anonymous wrote: On Saturday, 29 August 2015 at 23:34:47 UTC, Gary Willoughby wrote: But it might not be safe: http://forum.dlang.org/thread/ztefzijqhwrouzlag...@forum.dlang.org That link just takes me to this thread here again. Here's the correct

Re: Reading and converting binary file 2 bits at a time

2015-08-29 Thread Mike James via Digitalmars-d-learn
On Saturday, 29 August 2015 at 20:15:53 UTC, Marc Schütz wrote: Just cast to `Crumbs[]` directly: import std.bitmanip; import std.stdio; import std.file; struct Crumbs { mixin(bitfields!( ubyte, one, 2, ubyte, two, 2, ubyte,

Re: Reading and converting binary file 2 bits at a time

2015-08-29 Thread via Digitalmars-d-learn
Just cast to `Crumbs[]` directly: import std.bitmanip; import std.stdio; import std.file; struct Crumbs { mixin(bitfields!( ubyte, one, 2, ubyte, two, 2, ubyte, three, 2, ubyte, four, 2 )); } void

Re: Reading and converting binary file 2 bits at a time

2015-08-29 Thread Gary Willoughby via Digitalmars-d-learn
On Saturday, 29 August 2015 at 21:50:12 UTC, Mike James wrote: On Saturday, 29 August 2015 at 20:15:53 UTC, Marc Schütz wrote: Just cast to `Crumbs[]` directly: import std.bitmanip; import std.stdio; import std.file; struct Crumbs { mixin(bitfields!( ubyte,

Re: Reading and converting binary file 2 bits at a time

2015-08-29 Thread anonymous via Digitalmars-d-learn
On Saturday, 29 August 2015 at 23:34:47 UTC, Gary Willoughby wrote: But it might not be safe: http://forum.dlang.org/thread/ztefzijqhwrouzlag...@forum.dlang.org That link just takes me to this thread here again.

Re: Reading and converting binary file 2 bits at a time

2015-08-27 Thread Gary Willoughby via Digitalmars-d-learn
On Thursday, 27 August 2015 at 12:40:07 UTC, Mike James wrote: How about... A lot nicer. :)

Re: Reading and converting binary file 2 bits at a time

2015-08-27 Thread Mike James via Digitalmars-d-learn
On Thursday, 27 August 2015 at 09:00:02 UTC, Andrew Brown wrote: Hi, I need to read a binary file, and then process it two bits at a time. But I'm a little stuck on the first step. So far I have: import std.file; import std.stdio; void main(){ auto f = std.file.read(binaryfile); auto g

Re: Reading and converting binary file 2 bits at a time

2015-08-27 Thread Andrew Brown via Digitalmars-d-learn
On Thursday, 27 August 2015 at 09:26:55 UTC, rumbu wrote: On Thursday, 27 August 2015 at 09:00:02 UTC, Andrew Brown wrote: Hi, I need to read a binary file, and then process it two bits at a time. But I'm a little stuck on the first step. So far I have: import std.file; import std.stdio;

Re: Reading and converting binary file 2 bits at a time

2015-08-27 Thread Olivier Pisano via Digitalmars-d-learn
On Thursday, 27 August 2015 at 09:38:52 UTC, Andrew Brown wrote: That's lovely, thank you. One quick question, the length of the file is not a multiple of the length of ubyte, but the cast still seems to work. Do you know how it converts a truncated final section? Thanks again Andrew

Re: Reading and converting binary file 2 bits at a time

2015-08-27 Thread Gary Willoughby via Digitalmars-d-learn
On Thursday, 27 August 2015 at 09:38:52 UTC, Andrew Brown wrote: On Thursday, 27 August 2015 at 09:26:55 UTC, rumbu wrote: On Thursday, 27 August 2015 at 09:00:02 UTC, Andrew Brown wrote: Hi, I need to read a binary file, and then process it two bits at a time. But I'm a little stuck on the

Re: Reading and converting binary file 2 bits at a time

2015-08-27 Thread Rikki Cattermole via Digitalmars-d-learn
On 27/08/15 9:00 PM, Andrew Brown wrote: Hi, I need to read a binary file, and then process it two bits at a time. But I'm a little stuck on the first step. So far I have: import std.file; import std.stdio; void main(){ auto f = std.file.read(binaryfile); auto g = cast(bool[])f;

Re: Reading and converting binary file 2 bits at a time

2015-08-27 Thread rumbu via Digitalmars-d-learn
On Thursday, 27 August 2015 at 09:00:02 UTC, Andrew Brown wrote: Hi, I need to read a binary file, and then process it two bits at a time. But I'm a little stuck on the first step. So far I have: import std.file; import std.stdio; void main(){ auto f = std.file.read(binaryfile); auto g

Reading and converting binary file 2 bits at a time

2015-08-27 Thread Andrew Brown via Digitalmars-d-learn
Hi, I need to read a binary file, and then process it two bits at a time. But I'm a little stuck on the first step. So far I have: import std.file; import std.stdio; void main(){ auto f = std.file.read(binaryfile); auto g = cast(bool[]) f; writeln(g); } but all the values of g then