From: Stefan Rusterholz Date: 2009-01-29T09:03:04+09:00 Subject: Re: Bitwise question Andrew Barringer wrote: > I'm working on a project that has a bitmap of permissions and I need to > find out if a user has access. > > > > Given permissions bit mask of 0001C0200F02000000000 where each bit > represents a specific permission > > > > And a request for permissions check on bits [37, 12, 48] > > > > What's the best way to find out if user has access to all requested > permissions? Whatever 'best' is supposed to mean. Here is one way: requested_bits.all? { |bit| permissions[bit] == 1 } Regards Stefan -- Posted via http://www.ruby-forum.com/.