Compute the number of bytes that would be needed to encode a zigzag 32.

@param integer $value

@return integer
551031
public function computeZigzag32Size($value)
    {
        $varint = ($value << 1) ^ ($value >> 32 - 1);
        $size   = $this->computeVarintSize($varint);

        return $size;
    }
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;
    }
368783
public function encodeValue($value)
    {
        if (is_bool($value)) {
            return (int) $value;
        }

        if ($value instanceof Enum) {
            return $value->name();
        }

        if ($value instanceof Stream) {
            return json_encode($value->__toString());
        }

        return json_encode($value);
    }
750371
public static function packDouble($value)
    {
        $bin = pack('d', (float) $value);

        if (is_null(self::$little_endian)) {
            self::$little_endian = (pack('L', 1) == pack('V', 1));
        }

        if (self::$little_endian) {
            return $bin;
        }

        return self::swap($bin);
    }
1315022
function getByteSize($value)
    {
        // Copied from craft\helpers\App::phpConfigValueInBytes()
        if (!preg_match('/(\d+)(K|M|G)/i', $value, $matches)) {
            return (int)$value;
        }

        $value = (int)$matches[1];

        // Multiply!
        switch (strtolower($matches[2])) {
            case 'g':
                $value *= 1024;
            // no break
            case 'm':
                $value *= 1024;
            // no break
            case 'k':
                $value *= 1024;
            // no break
        }

        return $value;
    }
623181
public static function sizeInBytes($value)
    {
        $value = trim($value);
        $last = strtolower($value[strlen($value)-1]);

        switch($last) {
            case 'g':
                $value *= 1024;
            case 'm':
                $value *= 1024;
            case 'k':
                $value *= 1024;
        }

        return (int) $value;
    }
709234
private function getInt32Value($value)
    {
        if ($value > self::$int32Max || $value < -self::$int32Max - 1) {
            return false;
        }

        return (int) $value;
    }
1099469
public static function convertToBytes(string $value): int
    {
        $units = "BKMGT";
        $unit = preg_replace("/[^$units]/i", "", $value);
        $value = floatval($value);
        if ($unit) {
            $value *= pow(1024, stripos($units, $unit[0]));
        }

        return (int) $value;
    }
161757
public function transform($value)
    {
        if (function_exists('mb_check_encoding')) {
            $isUtf8 = mb_check_encoding($value, 'UTF-8');
        } else {
            $isUtf8 = $this->checkUtf8Encoding($value);
        }

        return  $isUtf8 ? $value : utf8_encode($value);
    }
1316064
public static function isIsbn($value)
    {
        $value = str_replace(array(' ', '-', '.'), '', $value);
        $length = strlen($value);
        $checkdigit = substr($value, -1);

        if ($length == 10) {

            if ( ! is_numeric(substr($value, -10, 9))) {
                return false;
            }

            $checkdigit = ( ! is_numeric($checkdigit)) ? $checkdigit : strtoupper($checkdigit);
            $checkdigit = ($checkdigit == 'X') ? '10' : $checkdigit;

            $sum = 0;

            for ($i = 0; $i < 9; $i++) {
                $sum = $sum + ($value[$i] * (10 - $i));
            }

            $sum = $sum + $checkdigit;
            $mod = $sum % 11;

            return ($mod == 0);

        } elseif ($length == 13) {

            $sum = 0;

            $sum =  $value[0] + ($value[1] * 3) + $value[2] + ($value[3] * 3) +
                    $value[4] + ($value[5] * 3) + $value[6] + ($value[7] * 3) +
                    $value[8] + ($value[9] * 3) + $value[10] + ($value[11] * 3);

            $mod = $sum % 10;

            $correct_checkdigit = 10 - $mod;
            $correct_checkdigit = ($correct_checkdigit == "10") ? "0" : $correct_checkdigit;

            return ($checkdigit == $correct_checkdigit);

        }

        return false;
    }
257927
private function convertInt($value)
    {
        if (!is_numeric($value)) {
            return $value;
        }

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

        return (int) $value;
    }
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;
    }
204229
private function encodeIDN($value)
	{
		if(preg_match_all('/^(.*):\/\/([^\/]+)(.*)$/',$value,$matches))
		{
			if(function_exists('idn_to_ascii'))
				$value=$matches[1][0].'://'.idn_to_ascii($matches[2][0]).$matches[3][0];
			else
			{
				require_once(Yii::getPathOfAlias('system.vendors.Net_IDNA2.Net').DIRECTORY_SEPARATOR.'IDNA2.php');
				$idna=new Net_IDNA2();
				$value=$matches[1][0].'://'.@$idna->encode($matches[2][0]).$matches[3][0];
			}
		}
		return $value;
	}
470763
private function getInt64Value($value)
    {
        if ($value > self::$int64Max || $value < -self::$int64Max - 1) {
            return false;
        }

        if (PHP_INT_SIZE !== 8 && ($value > self::$int32Max || $value < -self::$int32Max - 1)) {
            return (float) $value;
        }

        return (int) $value;
    }
827077
public static function ToUInt64( $value, $provider = null )
	{
		$result = Convert::ToInt( $value, $provider );
		if ( ! $result ) return null;
		return abs( $result );
	}
153109
public function encode($value)
    {

        $createdIv = $this->createIvSizeAndIvString();
        $createdKey = $this->createSpecialKey($createdIv);

        if (false !== $encrypted = @mcrypt_encrypt($this->algorithm, $createdKey, $value, $this->mode, $createdIv)) {

            return urlencode(base64_encode(
                serialize(
                    [
                        'iv'    => base64_encode($createdIv),
                        'key'   => base64_encode($createdKey),
                        'value' => trim(base64_encode($encrypted)),
                    ]
                )
            ));
        }

        return false;
    }
262924
public function decode(string $value): ?int
    {
        $value = $this->hashids->decode($value);

        if (is_array($value) && sizeof($value) > 0) {
            return $value[0];
        } else {
            return null;
        }
    }