counting matching bits / bitXnor
Bert Freudenberg
bert at freudenbergs.de
Tue Dec 18 10:00:31 UTC 2007
On Dec 17, 2007, at 19:04 , Cees de Groot wrote:
> On Dec 17, 2007 1:49 PM, Bert Freudenberg <bert at freudenbergs.de>
> wrote:
>>> 0 bitXnor: 0 -> -1
>>
>> And what exactly is wrong with that?
>>
> err... I'd expect '1' here?
How should that method know you are looking for 1-bit numbers only?
In your logic
2r0 bitXnor: 2r0 -> 2r1
2r00 bitXnor: 2r00 -> 2r11
which would be rather weird, wouldn't it?
-1 in two's complement is an endless string of 1s, so that's the
Right Thing.
If you want a "fixed-width" number then you can just #bitAnd: with
the number of bits you like:
-1 bitAnd: 2r1 -> 2r1
-1 bitAnd: 2r11 -> 2r11
- Bert -
More information about the Squeak-dev
mailing list
|