NOVINKA: Najžiadanejšie rekvalifikačné kurzy teraz s 50% zľavou + kurz AI ZADARMO. Nečakaj, táto ponuka dlho nevydrží! Zisti viac:

PHP - base_convert

Trieda

Koreň \ Bez triedy

Metóda - base_convert

(PHP 4, PHP 5, PHP 7)

The base_convert function converts a given number between various numeral systems.

Procedurálne

  • function base_convert (string $number, int $frombase, int $tobase) : string

Parametre

NázovDátový typPredvolená hodnotaPopis
$numberstring

The number to convert.

Invalid characters are silently ignored (without generating an error or throwing an exception). The string input is interpreted case-insensitively, both uppercase and lowercase letters can be entered.

$frombaseint

The base (radix) of a numerical system in which the input number is. This parameter has to be between 2 and 36 (incl.).

$tobaseint

The base (radix) of a numerical system to which the input number should be converted. This parameter has to be between 2 and 36 (incl.).

Mávratovej hodnoty

Vracia: string

The converted number as a string.

Príklady

<?php
echo ("28(dec) => hex: " . base_convert(28, 10, 16)."<br />");
echo ("123(bin) => dec: ". base_convert(123, 2, 10)."<br />");
echo ("28(dec) => unary: ". base_convert(5, 10, 1)."<br />");
echo ("28F(hex) => dec: ". base_convert("28F", 16, 10)."<br />");
echo ("45(dec) => bin:". base_convert(45, 10, 2)."<br />");
echo ("79(nonary) => quaternary:". base_convert(79, 9, 4)."<br />");
echo ("791567(nonary) => doudecimal: ". base_convert(791567, 9, 12)."<br />");

This example outputs (if viewed from a web browser):

28(dec) => hex: 1c
123(bin) => dec: 1



Warning:  base_convert(): Invalid `to base' (1) in (ommited) on line 4


28(dec) => unary:
28F(hex) => dec: 655
45(dec) => bin:101101
79(nonary) => quaternary:13
791567(nonary) => duodecimal: 2332a

Súvisiace manuály

      • function intval (mixed $var, int $base = 10) : int
      Aktivity