[Issue 4124] toString() for BitArray and more

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Jun 1 20:04:37 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=4124



--- Comment #8 from bearophile_hugs at eml.cc 2013-06-01 20:04:36 PDT ---
(In reply to comment #7)
> Commits pushed to master at https://github.com/D-Programming-Language/phobos
> 
> https://github.com/D-Programming-Language/phobos/commit/4f5079e4f8d38e1d469e4b28303553f36f49e33b
> Fixes Issue 4124 - Implement toString for BitArray.
> 
> https://github.com/D-Programming-Language/phobos/commit/9d331e2dc43a590c486c1b4862c0b1173b2f6799
> Merge pull request #1144 from AndrejMitrovic/Fix4124
> 
> Issue 4124 - Implement toString for BitArray.

Thank you. This introduces a good toString for BitArray. Then I will move
elsewhere the missing things.

I think this stuff can go in a single enhancement request because they are easy
and short to implement:
- reset all bits
- set all bits
- are all bit set?
- are all bit reset?
- set n-th bit (this can be a little more efficient than bs[n]=1;)
- reset n-th bit (this can be a little more efficient than bs[n]=1;)
- flip n-th bit

Maybe it's better to move this into a separated ER because it looks simple but
implementing a pop count very efficiently is not so easy:
- count set bits

----------------

Now (unlike "%s") "%b" produces a string output that's not usable to build a
new BitArray, maybe this is another worth enhancement request:


import std.stdio, std.bitmanip, std.conv, std.string;
void main() {
    BitArray b1;
    b1.init([0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1]);
    writefln("%b", b1); // Prints: 00001111_00001111
    BitArray b2;

    // Error: function std.bitmanip.BitArray.init (bool[] ba)
    // is not callable using argument types (string)
    b2.init("00001111_00001111");
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list