std.bitarray examples

Janice Caron caron800 at googlemail.com
Fri May 9 21:11:33 PDT 2008


On 10/05/2008, Janice Caron <caron800 at googlemail.com> wrote:
>  assigning x.n assigns the whole 16 bit number, while reading and
>  writing x.a to x.h will read or write the eight individual two-bit
>  fields.

Actually, I got that wrong. The example I gave is equivalent to C's:

    struct A
    {
        unsigned short n;
        unsigned int a : 2;
        unsigned int b : 2;
        unsigned int c : 2;
        unsigned int d : 2;
        unsigned int e : 2;
        unsigned int f : 2;
        unsigned int g : 2;
        unsigned int h : 2;
     }

I inadvertantly gave the impression that n overlaps a to h. It doesn't
- it's a separate variable. If you wanted n and a to h to overlap,
you'd have to use a struct inside a union.

Apologies for confusion. But anyway, std.bitmanip is what you want.



More information about the Digitalmars-d mailing list