Returns the smallest bit mask of all 1s such that ($toRepresent & mask) = $toRepresent
@param  integer $toRepresent must be an integer greater than or equal to 1
@return integer
771183
protected static function getMinimalBitMask($toRepresent)
    {
        if ($toRepresent < 1) {
            return false;
        }
        $mask = 0x1;
        while ($mask < $toRepresent) {
            $mask = ($mask << 1) | 1;
        }
        return $mask;
    }
795413
public function pause($bitmask = 0) : Int
    {
        if( ! empty($this->init) )
        {
            return curl_pause($this->init, Helper::toConstant($bitmask, 'CURLPAUSE_'));
        }

        return false;
    }
879142
public function getIsDecimalEven( $precision = false )
	{
		if ( ! $this->getIsDecimal() ) {
			return false;
		}

		if ( $precision === false ) $precision = $this->scale( $this->_value );
		if ( $precision < 0 ) $precision = $precision = 0;

		$decimalPart = $this->getDecimalPart();
		if ( $precision >= strlen( $decimalPart ) ) return false;

		// Get the portion of the decimal part affected by the scale value
		$decimalPart = substr( $decimalPart, $precision );
		return $decimalPart[0] % 2 === 0;
	}
982769
public function getIsCloserToNext( $precision = false, $mode = PHP_ROUND_HALF_UP )
	{
		if ( ! $this->getIsDecimal() ) {
			return false;
		}

		if ( $precision === false ) $precision = $this->scale( $this->_value );
		if ( $precision < 0 ) $precision = $precision = 0;

		$decimalPart = $this->getDecimalPart();
		if ( $precision >= strlen( $decimalPart ) ) return false;

		// Get the portion of the decimal part affected by the scale value
		$decimalPart = substr( $decimalPart, $precision );
		$result = bccomp( "0." . $decimalPart, "0.5", max( $this->scale( $decimalPart ), 1 ) );
		return $mode == PHP_ROUND_HALF_DOWN ? $result == 1 : $result >= 0;
	}
89842
public static function invertBits($n){
		$bits = \floor(\log($n, 2)) + 1;
		$mask = (1 << $bits) - 1;
		return $n ^ $mask;
	}
515746
public function makeMaskNo($maskNo, $width, $s, &$d, $maskGenOnly = false)
    {
        $b = 0;
        $bitMask = array();

        $fileName = Constants::QR_CACHE_DIR.'mask_'.$maskNo.DIRECTORY_SEPARATOR.'mask_'.$width.'_'.$maskNo.'.dat';

        if (Constants::QR_CACHEABLE) {
            if (file_exists($fileName)) {
                $bitMask = self::unserial(file_get_contents($fileName));
            } else {
                $bitMask = $this->generateMaskNo($maskNo, $width, $s, $d);
                if (!file_exists(Constants::QR_CACHE_DIR.'mask_'.$maskNo))
                    mkdir(Constants::QR_CACHE_DIR.'mask_'.$maskNo);
                file_put_contents($fileName, self::serial($bitMask));
            }
        } else {
            $bitMask = $this->generateMaskNo($maskNo, $width, $s, $d);
        }

        if ($maskGenOnly)
            return;

        $d = $s;

        for($y=0; $y<$width; $y++) {
            for($x=0; $x<$width; $x++) {
                if($bitMask[$y][$x] == 1) {
                    $d[$y][$x] = chr(ord($s[$y][$x]) ^ (int)$bitMask[$y][$x]);
                }
                $b += (int)(ord($d[$y][$x]) & 1);
            }
        }

        return $b;
    }
400414
private int computeNetworkPrefixFromMask(IPAddress mask) {
		
		int result = 0;
		int tmp = mask.getIPAddress();
		
		while ((tmp & 0x00000001) == 0x00000001) {
			result++;
			tmp = tmp >>> 1;
		}
		
		if (tmp != 0) {
			return -1;
		}
		
		return result;
	}
1030497
public function addOneToBytePreserveCarry($currentByte, &$carry) {
        for( $i = 0; $i < 8; $i++ ){
            $bitMaskValue = pow( 2, $i );
            $mask = chr( $bitMaskValue );
            $filteredBit = $currentByte & $mask;
            if( $carry == 1 && ord( $filteredBit ) == 0 ){
                $currentByte |= $mask;
                $carry = 0;
            }else if($carry == 1 && ord( $filteredBit ) >= 1){
                $flipMask = ~$mask;
                $currentByte &= $flipMask;
                //carry bit remains unchanged
            } 
        }
        return $currentByte;
    }
1290062
public function getBoundingBox($padding = 10)
    {
        $bare = imageftbbox(
                $this->getFontSize()
                , 0
                , $this->getFont()
                , $this->getString()
                , array('linespacing' => $this->getLineSpacing())
        );

        $a = deg2rad($this->getAngle());
        $ca = cos($a);
        $sa = sin($a);
        $rect = array();
        for ($i = 0; $i < 7; $i += 2) {
            $rect[$i] = round($bare[$i] * $ca + $bare[$i + 1] * $sa);
            $rect[$i + 1] = round($bare[$i + 1] * $ca - $bare[$i] * $sa);
        }

        $minX = min(array($rect[0], $rect[2], $rect[4], $rect[6]));
        $maxX = max(array($rect[0], $rect[2], $rect[4], $rect[6]));
        $minY = min(array($rect[1], $rect[3], $rect[5], $rect[7]));
        $maxY = max(array($rect[1], $rect[3], $rect[5], $rect[7]));

        $dx = $this->getCoordinate()->getX() - abs($minX) - 1;
        $dy = $this->getCoordinate()->getY() - abs($minY) - 1 + $this->getFontSize();

        $width = $maxX - $minX;
        $height = $maxY - $minY;

        $padding = (int) $padding;
        $dimension = new Dimension(
                $width + 2 + ($padding * 2)
                , $height + 2 + ($padding * 2)
        );
        $coordinate = new Coordinate(
                $dx - $padding
                , $dy - $padding
        );

        return new Box($dimension, $coordinate);
    }
20721
public static function operation_mask($stat1, $stat2)
    {
        $length = max(strlen($stat1), strlen($stat2));

        $stat1 = str_pad($stat1, 32, '0', STR_PAD_LEFT);
        $stat2 = str_pad($stat2, 32, '0', STR_PAD_LEFT);
        $stat1_or  = bindec(trim(str_replace("x", "0", $stat1)));
        $stat1_and = bindec(trim(str_replace("x", "1", $stat1)));
        $stat2_or  = bindec(trim(str_replace("x", "0", $stat2)));
        $stat2_and = bindec(trim(str_replace("x", "1", $stat2)));

        $decbin = decbin((((0 | $stat1_or) & $stat1_and) | $stat2_or) & $stat2_and);

        return str_pad($decbin, $length, '0', STR_PAD_LEFT);
    }
251560
public function cspn(string $mask, int $start = 0, int $length = null): int
    {
        if ($length === null) {
            $value = \strcspn($this->value, $mask, $start);
        } else {
            $value = \strcspn(
                $this->value,
                $mask,
                $start,
                $length
            );
        }

        return (int) $value;
    }
1169694
protected function get_num_parts($len)
    {
        $min_l = min($len, $this->minPart);
        $max_l = max($len, $this->maxPart);

        $n = $len - $min_l + 1;
        $d = $max_l - $min_l;
        $m = $n - $d;

        $s1 = $m * ($d + 1);
        $s2 = $d * ($d + 1) / 2;
        $s = $s1 + $s2;

        return (int) $s;
    }
67247
public function getVersionNumber($bits = null)
    {
        if (is_null($bits)) {
            return (int) str_replace('.', '', $this->version);
        }
        return implode('', $this->versionFromBits($bits));
    }
532898
public function getByteValue() : int
    {
        $bits = (array)$this->getValue();
        return array_reduce($bits, function ($carry, $item) {
            return $carry | (int)$item;
        }, 0);

    }
135003
public function getBitDepth($revision = null)
	{
		// Without revision, use current info
		if (!isset($revision)) {
			return (int)$this->info['bitdepth'];
		}

		// Obtain the properties of the revision
		if (($info = $this->getRevision($revision)) === null) {
			return -1;
		}

		return (int)$info['bitdepth'];
	}
1027479
public static function countOnBits($bits) {
		$tones = 0;
		for ($i = 0; $i < 12; $i++) {
			if (($bits & (1 << $i)) > 0) {
				$tones++;
			}
		}
		return $tones;
	}
1023643
public function getSegment($position = 1)
	{
		$position = ($position > 0) ? --$position : 0;

		if (array_key_exists($position, $this->pattern))
		{
			return $this->pattern[$position];
		}

		return false;
	}