Class: Integer
Instance Method Summary collapse
-
#and?(other, test: :any) ⇒ Boolean
Tests common bits in
this
ANDother
. -
#and_all?(other) ⇒ Boolean
True if
this
ANDother
isother
. -
#and_any?(other) ⇒ Boolean
True if
this
ANDother
is non-zero. -
#or?(other) ⇒ Boolean
True if
this
ORother
is non-zero. -
#xor?(other) ⇒ Boolean
True if
this
XORother
is non-zero.
Instance Method Details
#and?(other, test: :any) ⇒ Boolean
Tests common bits in this
AND other
.
test:
:any => true if any bits are set
:all => true if all bits are set
11 12 13 14 15 16 17 18 19 20 |
# 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) ⇒ Boolean
True if this
AND other
is other
.
i.e. if all set bits in other
are set in this
.
37 38 39 40 |
# File 'lib/mug/bittest.rb', line 37 def and_all? other return false if other.zero? self & other == other end |
#and_any?(other) ⇒ Boolean
True if this
AND other
is non-zero.
i.e. if any set bits in other
are set in this
.
27 28 29 30 |
# File 'lib/mug/bittest.rb', line 27 def and_any? other return false if other.zero? self & other != 0 end |
#or?(other) ⇒ Boolean
True if this
OR other
is non-zero.
45 46 47 |
# File 'lib/mug/bittest.rb', line 45 def or? other self | other != 0 end |
#xor?(other) ⇒ Boolean
True if this
XOR other
is non-zero.
52 53 54 |
# File 'lib/mug/bittest.rb', line 52 def xor? other self ^ other != 0 end |