Bits in reverse order in BitArray

Christian Manning cmanning999 at gmail.com
Mon Jul 4 11:03:35 PDT 2011


Hi, when I populate a BitArray using .init, the bits are in reverse 
order, although the bytes are in the correct order.
eg:

import std.stdio,std.bitmanip;

void main() {
     ubyte[] arr = [130,56,43,2];

     BitArray ba;
     ba.init(cast(void[])arr,32);
     foreach(b; ba)
        write(cast(ubyte) b); //bits in each byte reversed
                              //01000001000111001101010001000000
     writeln();

     ba.init(cast(void[])arr.reverse,32);
     foreach(b; ba.reverse)
        write(cast(ubyte) b); //bits printed in intended order
                              //10000010001110000010101100000010
     writeln();
}

Why does this happen?

Thanks


More information about the Digitalmars-d-learn mailing list