Reading and converting binary file 2 bits at a time
Andrew Brown via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Aug 31 11:00:52 PDT 2015
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!(
ubyte, "one", 2,
ubyte, "two", 2,
ubyte, "three", 2,
ubyte, "four", 2));
}
void main()
{
struct Crumb2
{
mixin(bitfields!(
ubyte, "one", 2,
ubyte, "two", 2,
ubyte, "three", 2,
ubyte, "four", 2));
}
writeln(Crumb1.sizeof, " ", Crumb2.sizeof);
}
outputs:
1 16
Is this correect behaviour?
Andrew
More information about the Digitalmars-d-learn
mailing list