counting matching bits / bitXnor

Bert Freudenberg bert at freudenbergs.de
Mon Dec 17 12:49:46 UTC 2007


On Dec 17, 2007, at 18:29 , Cees de Groot wrote:

> On Dec 17, 2007 1:34 PM, Paolo Bonzini <bonzini at gnu.org> wrote:
>> There's bitInvert, I think (I have no Squeak image here).  If you  
>> don't
>> have it, bitInvert is just "-1 - self".
>>
> Yup - and that draws in a sign and other ugliness. At least, in a
> direct implementation of bitXnor:
>
> bitXnor: anInteger
> 	" return bit-wise XNOR of two numbers. "
> 	
> 	^ (self bitAnd: anInteger) bitOr: (self bitInvert bitAnd:  
> anInteger bitInvert)
>
> 0 bitXnor: 0 -> -1

And what exactly is wrong with that?

- Bert -





More information about the Squeak-dev mailing list