BitArray - Is there one?

jerro a at a.com
Mon May 28 21:25:31 PDT 2012


>> That is, for one thing, sub is asymmetric :)
>
>  Hmm well subs would all happen at the 1 bit level. So let's 
> compare.
> xor
> 0 ^ 0 = 0
> 0 ^ 1 = 1
> 1 ^ 0 = 1
> 1 ^ 1 = 0
>
> sub
> 0 - 0 = 0
> 0 - 1 = -1 (or non-zero/true, truncates to 1)
> 1 - 0 = 1
> 1 - 1 = 0
>
>  Sorry, seems the same unless we are going with carry rules, 
> (at which point it is no longer bit arrays subs), it seems to 
> follow the xor rules.

I think you misunderstood. If you view a boolean as a one bit 
integer, then yes, xor is the same as subtraction. But what 
Dmitry probably meant is subtracting sets 
(http://en.wikipedia.org/wiki/Set_(mathematics)#Complements). So 
for bit arrays a and b the result of a - b would be a bit array 
where bit at index i is set if it is set in a and not set in b. 
That's also what documentation for std.bitmanip.BitArray 
currently says.


More information about the Digitalmars-d-learn mailing list