end
# Method to run bitwise AND (&) on two bit arrays and return the
- # result in a new bit array. Bits are copied if they exists in BOTH operands.
+ # result in the first bit array. Bits are copied if they exists in BOTH operands.
# 00111100 & 00001101 = 00001100
def &(ba)
raise BitArrayError, "uneven size of bit arrays: #{self.size} != #{ba.size}" if self.size != ba.size
- result = BitArray.new(ba.size)
+ self.byte_array = self.byte_array & ba.byte_array
- result.byte_array = self.byte_array & ba.byte_array
-
- result
+ self
end
# Method to run bitwise OR (|) on two bit arrays and return the
- # result in a new bit array. Bits are copied if they exists in EITHER operands.
+ # result in the first bit array. Bits are copied if they exists in EITHER operands.
# 00111100 | 00001101 = 00111101
def |(ba)
raise BitArrayError, "uneven size of bit arrays: #{self.size} != #{ba.size}" if self.size != ba.size
- result = BitArray.new(ba.size)
-
- result.byte_array = self.byte_array | ba.byte_array
+ self.byte_array = self.byte_array | ba.byte_array
- result
+ self
end
# Method to run bitwise XOR (^) on two bit arrays and return the
- # result in a new bit array. Bits are copied if they exists in ONE BUT NOT BOTH operands.
+ # result in the first bit array. Bits are copied if they exists in ONE BUT NOT BOTH operands.
# 00111100 ^ 00001101 = 00110001
def ^(ba)
raise BitArrayError, "uneven size of bit arrays: #{self.size} != #{ba.size}" if self.size != ba.size
- result = BitArray.new(ba.size)
-
- result.byte_array = self.byte_array ^ ba.byte_array
+ self.byte_array = self.byte_array ^ ba.byte_array
- result
+ self
end
# Method to convert a bit array to a string.