From: "David A. Black" Date: 2009-01-29T11:24:07+09:00 Subject: Re: Bitwise question Hi -- On Thu, 29 Jan 2009, Albert Schlef wrote: > Pascal J. Bourguignon wrote: >> Albert Schlef writes: >>> One, you need to do (1 << (b-1)). >> Bit 0 is the first bit. 2^0 = 1 > > I stand corrected. > >>> 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. > > All right, all right, you win ;-) I now see that [].all? too returns > 'true'. I could imagine wanting to handle the [] case conservatively. If the idea is to screen for permissions, and you want the default to be rejecting the person, then you'd probably want to reject an empty set of bits. [].all? does indeed always return true, so you'd have to do a separate empty? test somewhere. David -- David A. Black / Ruby Power and Light, LLC Ruby/Rails consulting & training: http://www.rubypal.com Coming in 2009: The Well-Grounded Rubyist (http://manning.com/black2) http://www.wishsight.com => Independent, social wishlist management!