Encodes an integer into hexadecimal representation.
@param int $integer The integer to encode
@param array $options The integer encoding options
@return string The PHP code representation for the integer
509713
public function encodeHexadecimal($integer, $options)
    {
        if ($options['hex.capitalize']) {
            return sprintf('%s0x%X', $this->sign($integer), abs($integer));
        }

        return sprintf('%s0x%x', $this->sign($integer), abs($integer));
    }
21414
public static function toInteger($value, array $options = array())
    {
        $options['precision'] = 0;
        $options['number_format'] = Zend_Locale_Format::STANDARD;
        return self::toNumber($value, $options);
    }
894057
def encode_params(params)
      return params.map do |p|
        if p.is_a?(Integer)
          Util.int_to_hex(p)
        else
          p
        end
      end
    end
1077312
protected function checkIfInteger(array $options, $optionName, $method)
    {
        if (!is_int($options[$optionName])) {
            throw new BadOptionFormatException($optionName, 'integer', $method);
        }
    }
1275242
public function encode($data, $options = 0) {
        $json = null;

        if ($data instanceof IArrayable) {
            $json = @json_encode($data->toArray(), $options);
        } else if ($data instanceof IJsonable) {
            $json = $data->toJson($options);
        } else if (is_array($data) || is_object($data)) {
            $json =  @json_encode($data, $options);
        } else {
            throw new InvalidDataTypeException(
                s('Can not convert data of type "%s" to json.', get_type($data))
            );
        }

        if ($json === false) {
            throw new JsonEncodeException(json_last_error_msg(), $data);
        }

        return $json;
    }
837972
public function encode($data, int $options = 0, int $depth = 512): string
    {
        // @7.3 use JSON_THROW_ON_ERROR
        $encoded = json_encode($data, $options, $depth);

        if (JSON_ERROR_NONE !== json_last_error()) {
            throw new EncodeException(json_last_error_msg());
        }

        return $encoded;
    }
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
    }
12051
public function toJson(int $options = 0)
    {
        $json = json_encode($this->toArray(), $options);
        if (JSON_ERROR_NONE !== json_last_error()) {
            throw new JsonEncodeException(json_last_error_msg());
        }

        return $json;
    }
770324
static void appendHex(StringBuilder out, Number number, FormatOptions options) {
    // We know there are no unexpected formatting flags (currently only upper casing is supported).
    boolean isUpper = options.shouldUpperCase();
    // We cannot just call Long.toHexString() as that would get negative values wrong.
    long n = number.longValue();
    // Roughly in order of expected usage.
    if (number instanceof Long) {
      appendHex(out, n, isUpper);
    } else if (number instanceof Integer) {
      appendHex(out, n & 0xFFFFFFFFL, isUpper);
    } else if (number instanceof Byte) {
      appendHex(out, n & 0xFFL, isUpper);
    } else if (number instanceof Short) {
      appendHex(out, n & 0xFFFFL, isUpper);
    } else if (number instanceof BigInteger) {
      String hex = ((BigInteger) number).toString(16);
      out.append(isUpper ? hex.toUpperCase(FORMAT_LOCALE) : hex);
    } else {
      // This will be caught and handled by the logger, but it should never happen.
      throw new RuntimeException("unsupported number type: " + number.getClass());
    }
  }
560283
private function authPrecheckObjectEncoding(&$options)
    {
        $tmp_object = $options[self::OSS_OBJECT];
        try {
            if (OssUtil::isGb2312($options[self::OSS_OBJECT])) {
                $options[self::OSS_OBJECT] = iconv('GB2312', "UTF-8//IGNORE", $options[self::OSS_OBJECT]);
            } elseif (OssUtil::checkChar($options[self::OSS_OBJECT], true)) {
                $options[self::OSS_OBJECT] = iconv('GBK', "UTF-8//IGNORE", $options[self::OSS_OBJECT]);
            }
        } catch (\Exception $e) {
            try {
                $tmp_object = iconv(mb_detect_encoding($tmp_object), "UTF-8", $tmp_object);
            } catch (\Exception $e) {
            }
        }
        $options[self::OSS_OBJECT] = $tmp_object;
    }
239580
public static function Base64Encode ($value, $options = []) {
		$to_encoding = isset($options['to_encoding']) ? $options['to_encoding'] : false;
		if ($to_encoding !== false) {
			$from_encoding = isset($options['from_encoding']) ? $options['from_encoding'] : static::DEFAULT_ENCODING;
			$value = mb_convert_encoding($value, $to_encoding, $from_encoding);
		}
		return base64_encode($value);
	}
795384
protected function formatNumber($number, NumberFormat $numberFormat, array $options = [])
    {
        $parsedPattern = $this->getParsedPattern($numberFormat, $options['style']);
        // Start by rounding the number, if rounding is enabled.
        if (is_int($options['rounding_mode'])) {
            $number = Calculator::round($number, $options['maximum_fraction_digits'], $options['rounding_mode']);
        }
        $negative = (Calculator::compare('0', $number, 12) == 1);
        // Ensure that the value is positive and has the right number of digits.
        $signMultiplier = $negative ? '-1' : '1';
        $number = bcdiv($number, $signMultiplier, $options['maximum_fraction_digits']);
        // Split the number into major and minor digits.
        $numberParts = explode('.', $number);
        $majorDigits = $numberParts[0];
        // Account for maximumFractionDigits = 0, where the number won't
        // have a decimal point, and $numberParts[1] won't be set.
        $minorDigits = isset($numberParts[1]) ? $numberParts[1] : '';

        if ($options['use_grouping'] && $parsedPattern->isGroupingUsed()) {
            // Reverse the major digits, since they are grouped from the right.
            $majorDigits = array_reverse(str_split($majorDigits));
            // Group the major digits.
            $groups = [];
            $groups[] = array_splice($majorDigits, 0, $parsedPattern->getPrimaryGroupSize());
            while (!empty($majorDigits)) {
                $groups[] = array_splice($majorDigits, 0, $parsedPattern->getSecondaryGroupSize());
            }
            // Reverse the groups and the digits inside of them.
            $groups = array_reverse($groups);
            foreach ($groups as &$group) {
                $group = implode(array_reverse($group));
            }
            // Reconstruct the major digits.
            $majorDigits = implode(',', $groups);
        }

        if ($options['minimum_fraction_digits'] < $options['maximum_fraction_digits']) {
            // Strip any trailing zeroes.
            $minorDigits = rtrim($minorDigits, '0');
            if (strlen($minorDigits) < $options['minimum_fraction_digits']) {
                // Now there are too few digits, re-add trailing zeroes
                // until the desired length is reached.
                $neededZeroes = $options['minimum_fraction_digits'] - strlen($minorDigits);
                $minorDigits .= str_repeat('0', $neededZeroes);
            }
        }

        // Assemble the final number and insert it into the pattern.
        $number = strlen($minorDigits) ? $majorDigits . '.' . $minorDigits : $majorDigits;
        $pattern = $negative ? $parsedPattern->getNegativePattern() : $parsedPattern->getPositivePattern();
        $number = preg_replace('/#(?:[\.,]#+)*0(?:[,\.][0#]+)*/', $number, $pattern);
        $number = $this->localizeNumber($number, $numberFormat);

        return $number;
    }
1061707
public static function currency($number, array $options = []) {
        $g11n = G11n::registry();

        if ($g11n->isEnabled()) {
            $options = array_merge(
                $g11n->current()->getFormatPatterns('number'),
                $g11n->current()->getFormatPatterns('currency'),
                $options
            );
        }

        return parent::currency($number, $options);
    }
444164
private function baseEncode($integer)
    {
        $b      = 61;
        $base   = '123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
        $r      = $integer % $b;
        $result = $base[$r];
        $q      = floor($integer / $b);
        while ($q) {
            $r      = $q % $b;
            $q      = floor($q / $b);
            $result = $base[$r].$result;
        }

        return $result;
    }
448547
public static function encode($value, $options = 0): string
	{
		$flags = \PHP_VERSION_ID >= 50400
			? (\JSON_UNESCAPED_UNICODE | \JSON_UNESCAPED_SLASHES | ($options & self::PRETTY
					? \JSON_PRETTY_PRINT
					: 0))
			: 0;

		if (\PHP_VERSION_ID < 50500) {
			$json = Callback::invokeSafe('json_encode', [$value, $flags], static function ($message) { // needed to receive 'recursion detected' error

				throw new JsonException($message);
			});
		} else {
			$json = \json_encode($value, $flags);
		}

		$error = \json_last_error();

		if ($error) {
			$message = static::$messages[$error] ?? (\PHP_VERSION_ID >= 50500 ? \json_last_error_msg() : 'Unknown error');

			throw new JsonException($message, $error);
		}

		$json = \str_replace(["\xe2\x80\xa8", "\xe2\x80\xa9"], ['\u2028', '\u2029'], $json);

		return $json;
	}
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;
        }
898966
private static function encodeInteger($int)
    {
        // Unsigned ints have a unsigned int major type and need to be converted to abs($val) - 1
        if($int < 0)
        {
            $major = MajorType::NEGATIVE_INT;
            $int = abs($int) - 1;
        }
        else
        {
            $major = MajorType::POSITIVE_INT;
        }

        return self::encodeIntValue($major, $int);
    }