Create a new BitArray using the concat operation

@param   BitArray  $bits1  A BitArray
@param   BitArray  $bits2  A BitArray

@return  BitArray  A new BitArray

@since   1.1.0
178143
public static function fromConcat(BitArray $bits1, BitArray $bits2)
	{
		$size = $bits1->size + $bits2->size;
		$concat = new BitArray($size);
		$concat->directCopy($bits1, 0, 0, $bits1->size);
		$concat->directCopy($bits2, $bits1->size, 0, $bits2->size);

		return $concat;
	}
1169513
public function write_bits($bits)
    {
        $value = 0;

        foreach ($bits as $n => $bit) {
            $bit = $bit ? 1 : 0;
            $value |= ($bit << $n);
        }

        $this->out .= chr($value);

        return $this;
    }
1076351
protected function _getx(&$data, $bits)
    {
        $value = null;

        if (strlen($data) >= $bits) {
            $value = substr($data, 0, $bits);
            $data = substr_replace($data, '', 0, $bits);
        }

        return $value;
    }
786309
@SuppressWarnings({"unchecked"})
    public static <T> T[] concat(Object[] array1, Object array2[], Class<T> componentType){
        Object newArray[] = (Object[])Array.newInstance(componentType, array1.length+array2.length);
        System.arraycopy(array1, 0, newArray, 0, array1.length);
        System.arraycopy(array2, 0, newArray, array1.length, array2.length);
        return (T[])newArray;
    }
628314
private function doSetBinaryBitsetLeBin($bitset): void
    {
        $size   = \strlen($this->bitset);
        $sizeIn = \strlen($bitset);

        if ($sizeIn < $size) {
            // add "\0" if the given bitset is not long enough
            $bitset .= \str_repeat("\0", $size - $sizeIn);
        } elseif ($sizeIn > $size) {
            if (\ltrim(\substr($bitset, $size), "\0") !== '') {
                throw new InvalidArgumentException('out-of-range bits detected');
            }
            $bitset = \substr($bitset, 0, $size);
        }

        // truncate out-of-range bits of last byte
        $lastByteMaxOrd = $this->enumerationCount % 8;
        if ($lastByteMaxOrd !== 0) {
            $lastByte         = $bitset[-1];
            $lastByteExpected = \chr((1 << $lastByteMaxOrd) - 1) & $lastByte;
            if ($lastByte !== $lastByteExpected) {
                throw new InvalidArgumentException('out-of-range bits detected');
            }

            $this->bitset = \substr($bitset, 0, -1) . $lastByteExpected;
        }

        $this->bitset = $bitset;
    }
140594
public function putBit(bool $bit):BitBuffer{
		$bufIndex = \floor($this->length / 8);

		if(\count($this->buffer) <= $bufIndex){
			$this->buffer[] = 0;
		}

		if($bit === true){
			$this->buffer[(int)$bufIndex] |= (0x80 >> ($this->length % 8));
		}

		$this->length++;

		return $this;
	}
693137
public function setbit($key, $offset, $bit) {
        return $this->returnCommand(['SETBIT'], $key, [$key, $offset, $bit]);
    }
267177
private function mergeValues(array $set1, array $set2)
    {
        // `$set2` may be empty if an array value is chunked at the end of the
        // list. Handling it normally results in an additional `null` value
        // being pushed onto the list of values. Since this method is only
        // called in cases where two chunks must be merged, we can safely
        // short-circuit the operation of the second chunk is empty.
        if (empty($set2)) {
            return $set1;
        }

        $lastItemSet1 = array_pop($set1);
        $firstItemSet2 = array_shift($set2);
        $item = $firstItemSet2;

        if (is_string($lastItemSet1) && is_string($firstItemSet2)) {
            $item = $lastItemSet1 . $firstItemSet2;
        } elseif (is_array($lastItemSet1)) {
            $item = $this->mergeValues($lastItemSet1, $firstItemSet2);
        } else {
            array_push($set1, $lastItemSet1);
        }

        array_push($set1, $item);
        return array_merge($set1, $set2);
    }
248990
public function applyXor(BitArray $bits)
	{
		if ($this->size == $bits->size)
		{
			$length = strlen($this->data);

			for ($index = 0; $index < $length; $index++)
			{
				$this->data[$index] = chr(ord($this->data[$index]) ^ ord($bits->data[$index]));
			}

			return $this;
		}
		else
		{
			throw new \InvalidArgumentException('Argument must be of equal size');
		}
	}
1092950
public static function arrayMergeRecursiveUnique($array1, $array2)
    {
        if (empty($array1)) {
            // Optimize the base case
            return $array2;
        }

        foreach ($array2 as $key => $value) {
            if (is_array($value) && isset($array1[$key]) && is_array($array1[$key])) {
                $value = static::arrayMergeRecursiveUnique($array1[$key], $value);
            }
            $array1[$key] = $value;
        }

        return $array1;
    }
303420
public static byte bitsToByte(String bits) {
        byte b = 0;
        for (int i = bits.length() - 1, j = 0; i >= 0; i--, j++) {
            char c = bits.charAt(i);
            if (c == '1') {
                b += (1 << j);
            }
        }
        return b;
    }
82676
private static byte[] toByteArrayReverse(BitSet bits) {
        byte[] bytes = new byte[bits.length() / 8 + 1];
        for (int i = 0; i < bits.length(); i++) {
            if (bits.get(i)) {
                final int value = bytes[i / 8] | (1 << (7 - (i % 8)));
                bytes[i / 8] = (byte) value;
            }
        }
        return bytes;
    }
457042
public function bitOr( $value1, $value2 )
    {
        $value1 = $this->getIdentifier( $value1 );
        $value2 = $this->getIdentifier( $value2 );
        return "( {$value1} | {$value2} )";
    }
1052189
public static function sub($int1, $int2)
    {
        if (!static::is($int1) || !static::is($int2)) {
            throw new \InvalidArgumentException("The \$int1 and \$int2 parameters must be of type int.");
        }

        return ($int1 - $int2);
    }
1256168
protected static function bits2str($bits) 
    {
        $str = '';
        while ($bits) {
            $flag = substr($bits, 0, 1);
            $bits = substr($bits, 1);

            if ($flag == 1) {
                $byte = substr($bits, 0, 8);
                $bits = substr($bits, 8);

                if ($bits || strlen($code) == 8) {
                    $int  = base_convert($byte, 2, 10);
                    $char = chr($int);
                    $str .= $char;
                }
            } else {
                $code = substr($bits, 0, 3);
                $bits = substr($bits, 3);

                if ($bits || strlen($code) == 3) {
                    $pos  = strpos(self::$_binary, "0$code|");
                    $str .= substr(self::$_encode, $pos/5, 1);
                }
            }
        }

        return $str;
    }
1205866
private function bigMul($num1, $num2)
    {
        if ($num1 < 10 || $num2 < 10) {
            return $num1 * $num2;
        }

        $m = max([$this->getBit($num1), $this->getBit($num2)]);
        $m2 = floor($m / 2);

        $high1 = $this->getHighBitPart($num1, $m2);
        $low1 = $this->getLowBitPart($num1, $m2);

        $high2 = $this->getHighBitPart($num2, $m2);
        $low2 = $this->getLowBitPart($num2, $m2);

        $z2 = $this->bigMul($high1, $high2);
        $z0 = $this->bigMul($low1, $low2);
        $z1 = $this->bigMul(($high1 + $low1), ($high2 + $low2)) - $z2 - $z0;
        return $z2 * pow(10, 2 * $m2) + $z1 * pow(10, $m2) + $z0;
    }
793816
public static function haveSameKeys(array $array1, array $array2)
    {
        return self::hasAllKeys($array1, array_keys($array2)) && self::hasAllKeys($array2, array_keys($array1)) ? true : false;
    }