private function bitwise(string $operator, string $a, string $b) : string
    {
        $this->init($a, $b, $aDig, $bDig, $aNeg, $bNeg);

        $aBin = $this->toBinary($aDig);
        $bBin = $this->toBinary($bDig);

        $aLen = \strlen($aBin);
        $bLen = \strlen($bBin);

        if ($aLen > $bLen) {
            $bBin = \str_repeat("\x00", $aLen - $bLen) . $bBin;
        } elseif ($bLen > $aLen) {
            $aBin = \str_repeat("\x00", $bLen - $aLen) . $aBin;
        }

        if ($aNeg) {
            $aBin = $this->twosComplement($aBin);
        }
        if ($bNeg) {
            $bBin = $this->twosComplement($bBin);
        }

        switch ($operator) {
            case 'and':
                $value = $aBin & $bBin;
                $negative = ($aNeg and $bNeg);
                break;

            case 'or':
                $value = $aBin | $bBin;
                $negative = ($aNeg or $bNeg);
                break;

            case 'xor':
                $value = $aBin ^ $bBin;
                $negative = ($aNeg xor $bNeg);
                break;

            // @codeCoverageIgnoreStart
            default:
                throw new \InvalidArgumentException('Invalid bitwise operator.');
            // @codeCoverageIgnoreEnd
        }

        if ($negative) {
            $value = $this->twosComplement($value);
        }

        $result = $this->toDecimal($value);

        return $negative ? $this->neg($result) : $result;
    }
private function bitwise(string $operator, string $a, string $b) : string
    {
        $this->init($a, $b, $aDig, $bDig, $aNeg, $bNeg);

        $aBin = $this->toBinary($aDig);
        $bBin = $this->toBinary($bDig);

        $aLen = \strlen($aBin);
        $bLen = \strlen($bBin);

        if ($aLen > $bLen) {
            $bBin = \str_repeat("\x00", $aLen - $bLen) . $bBin;
        } elseif ($bLen > $aLen) {
            $aBin = \str_repeat("\x00", $bLen - $aLen) . $aBin;
        }

        if ($aNeg) {
            $aBin = $this->twosComplement($aBin);
        }
        if ($bNeg) {
            $bBin = $this->twosComplement($bBin);
        }

        switch ($operator) {
            case 'and':
                $value = $aBin & $bBin;
                $negative = ($aNeg and $bNeg);
                break;

            case 'or':
                $value = $aBin | $bBin;
                $negative = ($aNeg or $bNeg);
                break;

            case 'xor':
                $value = $aBin ^ $bBin;
                $negative = ($aNeg xor $bNeg);
                break;

            // @codeCoverageIgnoreStart
            default:
                throw new \InvalidArgumentException('Invalid bitwise operator.');
            // @codeCoverageIgnoreEnd
        }

        if ($negative) {
            $value = $this->twosComplement($value);
        }

        $result = $this->toDecimal($value);

        return $negative ? $this->neg($result) : $result;
    }
private function bitwise ( string $ operator , string $ a , string $ b ) : string { $ this -> init ( $ a , $ b , $ aDig , $ bDig , $ aNeg , $ bNeg ) ; $ aBin = $ this -> toBinary ( $ aDig ) ; $ bBin = $ this -> toBinary ( $ bDig ) ; $ aLen = \ strlen ( $ aBin ) ; $ bLen = \ strlen ( $ bBin ) ; if ( $ aLen > $ bLen ) { $ bBin = \ str_repeat ( "\x00" , $ aLen - $ bLen ) . $ bBin ; } elseif ( $ bLen > $ aLen ) { $ aBin = \ str_repeat ( "\x00" , $ bLen - $ aLen ) . $ aBin ; } if ( $ aNeg ) { $ aBin = $ this -> twosComplement ( $ aBin ) ; } if ( $ bNeg ) { $ bBin = $ this -> twosComplement ( $ bBin ) ; } switch ( $ operator ) { case 'and' : $ value = $ aBin & $ bBin ; $ negative = ( $ aNeg and $ bNeg ) ; break ; case 'or' : $ value = $ aBin | $ bBin ; $ negative = ( $ aNeg or $ bNeg ) ; break ; case 'xor' : $ value = $ aBin ^ $ bBin ; $ negative = ( $ aNeg xor $ bNeg ) ; break ; // @codeCoverageIgnoreStart default : throw new \ InvalidArgumentException ( 'Invalid bitwise operator.' ) ; // @codeCoverageIgnoreEnd } if ( $ negative ) { $ value = $ this -> twosComplement ( $ value ) ; } $ result = $ this -> toDecimal ( $ value ) ; return $ negative ? $ this -> neg ( $ result ) : $ result ; }
Performs a bitwise operation on a decimal number.

@param string $operator The operator to use, must be "and", "or" or "xor".
@param string $a        The left operand.
@param string $b        The right operand.

@return string
Performs a bitwise operation on a decimal number .