Bug 18133 – BitArray constructors are poorly documented.
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2017-12-27T21:21:04Z
Last change time
2018-03-12T05:09:53Z
Assigned to
Jakub Łabaj
Creator
Simen Kjaeraas
Comments
Comment #0 by simen.kjaras — 2017-12-27T21:21:04Z
unittest
{
import std.bitmanip : BitArray;
import std.format : format;
enum input = "0b11001111_11010010";
auto ba = BitArray([mixin(input)], 16);
assert(format("0b%b", ba) == input);
}
Since D has binary literals, it's non-intuitive and thus bug-prone that the output of BitArray.toString prints the bits in the opposite order that's used in said literals.
Comment #1 by petar.p.kirov — 2017-12-29T10:25:47Z
Personally, I wouldn't say it's a bug - this particular constructor takes a raw data that is mapped onto the content of the BitArray. This is consistent (i.e. is exactly the opposite) with the cast operator to `void[]`:
size_t val = 0b11001111_11010010;
void[] arr = [val];
auto ba = BitArray([val], 16);
assert(cast(void[]) ba == [val]);
Definitely, there should be a note in the doc saying it works in that way - I'm going to add it.
Comment #3 by uaaabbjjkl — 2018-02-02T18:28:09Z
Because this isn't a printing bug, but rather problem with poorly documented constructor, I renamed the issue name.
Comment #4 by github-bugzilla — 2018-03-12T05:09:53Z