Bitwise AND.

@param $value mixed anything that can be converted into an IP object

@return IP
488824
public function bit_and($value): IP
    {
        if (!$value instanceof self) {
            $value = new static($value);
        }

        return new static(gmp_and($this->ip, $value->ip));
    }
33192
public function get($value) {
        //TODO throw exception instead?!
        if (\is_int($value)) {
            $info = $this->getIndexAndMask($value);
            $i = $info["i"];
            $k = $info["k"];

            $flag = 1;
            $flag = $flag << $k;

            if (isset($this->array[$i])) return (($this->array[$i] & $flag) !== 0);
            return false;
        }
        return false;
    }
426497
public function bitAnd( $value1, $value2 )
    {
        $value1 = $this->getIdentifier( $value1 );
        $value2 = $this->getIdentifier( $value2 );
        return "( {$value1} & {$value2} )";
    }
1233865
public function filter($value)
    {
        if ($this->isBinary($value)) {
            return base64_decode(substr($value, BinaryInfo::BINARY_BODY_PREFIX_LENGTH), true);
        }

        return $value;
    }
972426
public function appendInt16($value)
    {
        $s = pack("s", $value);
        return $this->append(self::$isLittleEndian ? self::swapEndian16($s) : $s);
    }
426301
public static function ipv4(string $value):bool
    {
        $value = (string)$value;
        $valid = filter_var($value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4);
        return $valid !== false;
    }
249839
public static function ipv6(string $value):bool
    {
        $value = (string)$value;
        $valid = filter_var($value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6);
        return $valid !== false;
    }
679699
public static function ip(string $value):bool
    {
        $value = (string)$value;
        $valid = filter_var($value, FILTER_VALIDATE_IP);
        return $valid !== false;
    }
772681
protected function intToBinary($value)
    {
        $nbytes = 0;
        if ($value > 0xFF) {
            $nbytes = 1; // 1 byte integer
        }
        if ($value > 0xFFFF) {
            $nbytes += 1; // 4 byte integer
        }
        if ($value > 0xFFFFFFFF) {
            $nbytes += 1; // 8 byte integer
        }
        if ($value < 0) {
            $nbytes = 3; // 8 byte integer, since signed
        }

        $bdata = self::typeBytes("1", $nbytes); // 1 is 0001, type indicator for integer
        $buff = "";

        if ($nbytes < 3) {
            if ($nbytes == 0) {
                $fmt = "C";
            } elseif ($nbytes == 1) {
                $fmt = "n";
            } else {
                $fmt = "N";
            }

            $buff = pack($fmt, $value);
        } else {
            if (PHP_INT_SIZE > 4) {
              // 64 bit signed integer; we need the higher and the lower 32 bit of the value
                $high_word = $value >> 32;
                $low_word = $value & 0xFFFFFFFF;
            } else {
                // since PHP can only handle 32bit signed, we can only get 32bit signed values at this point - values above 0x7FFFFFFF are
                // floats. So we ignore the existance of 64bit on non-64bit-machines
                if ($value < 0) {
                    $high_word = 0xFFFFFFFF;
                } else {
                    $high_word = 0;
                }
                $low_word = $value;
            }
            $buff = pack("N", $high_word).pack("N", $low_word);
        }

        return $bdata.$buff;
    }
346568
public function validateValue($value)
    {
        list($domain, $ip) = explode('/', $value, 2);
        if (($error = (new DomainValidator())->validateValue($domain)) !== null) {
            return $error;
        }
        if ($ip !== null && ($error = (new IpValidator())->validateValue($ip)) !== null) {
            return $error;
        }

        return null;
    }
657410
protected function castValue($value)
    {
        switch ($value) {
            case 'false':
                return false;

            case 'true':
                return true;
        }

        if (is_numeric($value)) {
            $value = intval($value);
        }

        return $value;
    }
745483
public function writeInt8(int $value): self
    {
        $this->bytes .= Writer::bit8($value);

        return $this;
    }
300804
protected function detectInt($value)
    {
        if ($value < 0) {
            // int
            if ($value >= self::INT8_MIN) {
                return self::BINN_INT8;
            } else if ($value >= self::INT16_MIN) {
                return self::BINN_INT16;
            } else if ($value >= self::INT32_MIN) {
                return self::BINN_INT32;
            } else {
                return self::BINN_INT64;
            }
        } else {
            // uint
            if ($value <= self::UINT8_MAX) {
                return self::BINN_UINT8;
            } else if ($value <= self::UINT16_MAX) {
                return self::BINN_UINT16;
            } else if ($value <= self::UINT32_MAX) {
                return self::BINN_UINT32;
            } else {
                return self::BINN_UINT64;
            }
        }
    }
619135
public static function ip($value, $allowPrivate = true)
    {
        return $allowPrivate
            ? Validator::ip()->validate($value)
            : Validator::ip(FILTER_FLAG_NO_PRIV_RANGE)->validate($value);
    }
15594
public function transform($value)
    {
        // Not numeric and isn't blank (a value was actually provided)
        if ( ! is_numeric($value) && ! $this->isBlank($value)) {
            throw new LogicException("A valid integer is required.");
        }

        if ($value !== null) {
            return (int) $value;
        }

        return $value;
    }
120789
protected function bit(string $operator, int $value) : self
    {
        $this->requiresCurrentField();
        $this->newObj['$bit'][$this->currentField][$operator] = $value;
        return $this;
    }
893042
public static function encode($value)
    {
        $encoded = '';
        $vlq = self::toVLQSigned($value);

        do {
            $digit = $vlq & self::VLQ_BASE_MASK;
            $vlq >>= self::VLQ_BASE_SHIFT;

            if ($vlq > 0) {
                $digit |= self::VLQ_CONTINUATION_BIT;
            }

            $encoded .= Base64::encode($digit);
        } while ($vlq > 0);

        return $encoded;
    }