class Integer
Public Instance Methods
and?(other, test: :any)
click to toggle source
Tests common bits in this
AND other
.
test:
:any => true if any bits are set :all => true if all bits are set
# File lib/mug/bittest.rb, line 11 def and? other, test: :any case test.to_sym when :any and_any? other when :all and_all? other else raise ArgumentError, "invalid value for 'test' (given #{test.inspect}, should be :any or :all)" end end
and_all?(other)
click to toggle source
True if this
AND other
is other
.
i.e. if all set bits in other
are set in this
.
# File lib/mug/bittest.rb, line 37 def and_all? other return false if other.zero? self & other == other end
and_any?(other)
click to toggle source
True if this
AND other
is non-zero.
i.e. if any set bits in other
are set in this
.
# File lib/mug/bittest.rb, line 27 def and_any? other return false if other.zero? self & other != 0 end
or?(other)
click to toggle source
True if this
OR other
is non-zero.
# File lib/mug/bittest.rb, line 45 def or? other self | other != 0 end
xor?(other)
click to toggle source
True if this
XOR other
is non-zero.
# File lib/mug/bittest.rb, line 52 def xor? other self ^ other != 0 end