From: pjb@... (Pascal J. Bourguignon) Date: 2009-01-29T09:42:37+09:00 Subject: Re: Bitwise question Albert Schlef writes: > Pascal J. Bourguignon wrote: >> (def check(permissions,bits) >> (bits . inject(true) { | r , b | >> (r and (0 != (permissions & (1 << b)))) >> }) >> end) > > > That what happens when one spends his time typing parenthesis instead of > programming, my dear Pascal. I managed to count at least two bugs there. > One, you need to do (1 << (b-1)). Bit 0 is the first bit. 2^0 = 1 > Two, if you pass [] as the bits, the > result will be 'true'. Which is of course the correct answer. All the bits in the empty set are in any bitfield. There is no bit in the empty set hat are not in a given bitfield. -- __Pascal Bourguignon__