DanC wrote:
> I hope this isn't a stupid question but I don't understand the 01010 =
> 10 part?

I was simply showing the 01010 in binary (0b01010) is equal to 10 in 
decimal.

So in order to create a bit mask all you need to store is a simple 
integer (Fixnum).

Example 1:

Say your bit mask value is:
x = 0b01010
=> 10

If you want to know if the second bit from the left is set create a mask 
with the desired bit set:

mask = 0b01000
=> 8

then bit-wise AND the value with the mask:

x & mask > 0
=> true

mask = 0b00100
x & mask > 0 # is the third bit from left set?
=> false

Example 2:
http://pastie.textmate.org/private/acweqtdqm3jdhtufe4ag
-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to