PHP - dechex
Trieda
Metóda - dechex
(PHP 4, PHP 5, PHP 7)
This function converts a decimal number to a hexadecimal number. The base_convert function which is universal can be used instead.
Procedurálne
- function dechex (int $number) : string
Parametre
| Názov | Dátový typ | Predvolená hodnota | Popis |
|---|---|---|---|
| $number | int | The decimal number to convert. Note: This function is designed to work only with unsigned numbers. If a negative number is given, it will be treated like an unsigned number. |
Mávratovej hodnoty
Vracia: string
The resulting hexadecimal number represented as a string.
Príklady
<?php
$array = [156, -137, "itnetwork", "148", 11.1, 11];
foreach ($array as $value) {
echo ("'$value' (dec) => hex: '". dechex($value)."'<br>");
}
This example outputs (if viewed from a web browser):
'156' (dec) => hex: '9c' '-137' (dec) => hex: 'ffffffffffffff77' 'itnetwork' (dec) => hex: '0' '148' (dec) => hex: '94' '11.1' (dec) => hex: 'b' '11' (dec) => hex: 'b'
Súvisiace manuály
- function base_convert (string $number, int $frombase, int $tobase) : string
- function decbin (int $number) : string
- function decoct (int $number) : string
- function hexdec (string $hex_string) : number
