Calculate the byte needed for a „normal” integer value
@param integer $int The integer value
@return integer The number of bytes needed + 1 (because of the „marker byte”)
427417
public static function bytesInt($int)
    {
        $nbytes = 1;

        if ($int > 0xFF) {
            $nbytes += 1; // 2 byte integer
        }
        if ($int > 0xFFFF) {
            $nbytes += 2; // 4 byte integer
        }
        if ($int > 0xFFFFFFFF) {
            $nbytes += 4; // 8 byte integer
        }
        if ($int < 0) {
            $nbytes += 7; // 8 byte integer (since it is signed)
        }

        return $nbytes + 1; // one „marker” byte
    }
875985
public function writeInt($int) {

    			// Note that this is simply a sanity check of the conversion algorithm;
    			// when live this sanity check should be disabled (overflow check handled in this.writeAMFData).
    			/*if ( ( ( $int & 0x70000000 ) != 0 ) && ( ( $int & 0x80000000 ) == 0 ) )
    				throw new Exception ( 'Integer overflow during Int32 to AMF3 conversion' );*/

    			if ( ( $int & 0xffffff80 ) == 0 )
    			{
    				$this->stream->writeByte ( $int & 0x7f );

    				return;
    			}

    			if ( ( $int & 0xffffc000 ) == 0 )
    			{
    				$this->stream->writeByte ( ( $int >> 7 ) | 0x80 );
    				$this->stream->writeByte ( $int & 0x7f );

    				return;
    			}

    			if ( ( $int & 0xffe00000 ) == 0 )
    			{
    				$this->stream->writeByte ( ( $int >> 14 ) | 0x80 );
    				$this->stream->writeByte ( ( $int >> 7 ) | 0x80 );
    				$this->stream->writeByte ( $int & 0x7f );

    				return;
    			}

    			$this->stream->writeByte ( ( $int >> 22 ) | 0x80 );
    			$this->stream->writeByte ( ( $int >> 15 ) | 0x80 );
    			$this->stream->writeByte ( ( $int >> 8 ) | 0x80 );
    			$this->stream->writeByte ( $int & 0xff );

    			return;
        }
1085599
private function int3Type6($Int)
    {
        $Tail = $Int % 10;
        $Tail2 = $Int % 100;
        if ($Tail === 0 || ($Tail2 >= 10 && $Tail2 <= 20)) {
            return 2;
        }
        return ($Tail === 1) ? 0 : 1;
    }
843860
public static function calculate( $integer )
	{
		Deprecation::getInstance()
			->setErrorVersion( '0.8.5' )
			->setExceptionVersion( '0.9' )
			->message( sprintf(
				'Please use %s (%s) instead',
				'public library "CeusMedia/Math"',
			 	'https://packagist.org/packages/ceus-media/math'
			) );
		if( $integer < 0 )
			throw new InvalidArgumentException( "Factorial is defined for positive natural Numbers only" );
		else if( !is_int( $integer ) )
			throw new InvalidArgumentException( "Factorial is defined for natural Numbers (Integer) only" );
		else if( $integer == 0 )
			return 1;
		else
			return $integer * self::calculate( $integer - 1 );
		return 0;
	}
887747
public static function getByte(&$p)
    {
        $r = static::bytes2int($p{0});
        $p = mb_orig_substr($p, 1);
        return (int)$r;
    }
258224
protected function packSize($size)
    {
        return ($size <= 127)
            ? $this->pack(self::BINN_UINT8, $size)
            : $this->getInt32Binsize($size);
    }
86390
public static function getMemoryLimit(int $default = 128): int
    {
        $limit = ini_get('memory_limit');

        if (-1 === $limit) {
            return $default * self::SHORTHAND[self::MEGABYTE]; //default
        }

        if (is_numeric($limit)) {
            return (int)$limit;
        }

        return (int)substr($limit, 0, -1) * self::SHORTHAND[strtolower(substr($limit, -1))];
    }
380127
private function intToByteString(int $int): string
    {
        $result = [];
        while (0 !== $int) {
            $result[] = chr($int & 0xFF);
            $int >>= 8;
        }
        
        return str_pad(implode(array_reverse($result)), 8, "\000", STR_PAD_LEFT);
    }
1259560
public function toBytes($size)
    {
        if (is_numeric($size)) {
            return (int) $size;
        }

        $unit = strtoupper(substr($size, -2));

        $value = substr($size, 0, -1);
        if (!is_numeric($value)) {
            $value = substr($value, 0, -1);
        }

        $exponent = array_search($unit, $this->units);
        return (int)($value * pow(1024, $exponent));
    }
481781
public static function arabic2roman(int $int): string
	{
		$int = (int) $int;

		if($int < 1 || $int > 3999)
		{
			throw new InvalidArgumentException('The number must be between 1 and 3999.');
		}

		$numerals =
		[
			'M'  => 1000,
			'CM' => 900,
			'D'  => 500,
			'CD' => 400,
			'C'  => 100,
			'XC' => 90,
			'L'  => 50,
			'XL' => 40,
			'X'  => 10,
			'IX' => 9,
			'V'  => 5,
			'IV' => 4,
			'I'  => 1,
		];

		$romanNumeral = '';

		foreach($numerals as $roman => $arabic)
		{
			$count = (int) ($int / $arabic);

			if($count === 0)
			{
				continue;
			}

			$romanNumeral .= str_repeat($roman, $count);

			$int %= $arabic;

			if($int === 0)
			{
				break;
			}
		}

		return $romanNumeral;
	}
1034442
private function normalize_int($size)
    {
        if (is_numeric($size)) {
            return (int)$size;
        }

        $letter = substr($size, -1);
        $size = (int)$size;

        switch ($letter) {
            case 'M': case 'm': return $size * 1048576;
            case 'K': case 'k': return $size * 1024;
            case 'G': case 'g': return $size * 1073741824;
        }
    }
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;
    }
602820
private function int3Type5($Int)
    {
        if ($Int === 1) {
            return 0;
        }
        $Tail = $Int % 10;
        $Tail2 = $Int % 100;
        return ($Tail >= 2 && $Tail <= 4 && ($Tail2 < 10 || $Tail2 >= 20)) ? 1 : 2;
    }
62014
public function writeInteger($int)
    {
        if (($int & 0xffffff80) == 0) {
            $this->_stream->writeByte($int & 0x7f);
            return $this;
        }

        if (($int & 0xffffc000) == 0 ) {
            $this->_stream->writeByte(($int >> 7 ) | 0x80);
            $this->_stream->writeByte($int & 0x7f);
            return $this;
        }

        if (($int & 0xffe00000) == 0) {
            $this->_stream->writeByte(($int >> 14 ) | 0x80);
            $this->_stream->writeByte(($int >> 7 ) | 0x80);
            $this->_stream->writeByte($int & 0x7f);
            return $this;
        }

        $this->_stream->writeByte(($int >> 22 ) | 0x80);
        $this->_stream->writeByte(($int >> 15 ) | 0x80);
        $this->_stream->writeByte(($int >> 8 ) | 0x80);
        $this->_stream->writeByte($int & 0xff);
        return $this;
    }
947777
private function modNn(int $x) : int
    {
        while ($x >= $this->blockSize) {
            $x -= $this->blockSize;
            $x = ($x >> $this->symbolSize) + ($x & $this->blockSize);
        }

        return $x;
    }
880188
public function getSeason($asInt = true)
    {
        $value = fmod($this->getRyzomSeason(), 4) + 1;

        return $asInt ? (int) $value : $value;
    }
1203732
public static function fromInteger(int $int, ?int $minLength = null)
    {
        $pieces = str_split(decbin($int), 8);
        $num = count($pieces);

        if ($num === 1 && strlen($pieces[0]) !== 8) {
            $pieces[0] = str_pad($pieces[0], 8, '0', STR_PAD_LEFT);
        } elseif ($num > 0 && strlen($pieces[$num - 1]) !== 8) {
            $pieces[$num - 1] = str_pad($pieces[$num - 1], 8, '0', STR_PAD_RIGHT);
        }

        $bitstring = implode('', $pieces);
        if ($minLength && strlen($bitstring) < $minLength) {
            $bitstring = str_pad($bitstring, $minLength, '0');
        }

        return new self($bitstring);
    }