dechex
Description
Syntax
dechex(
int $num
): stringParameters
num
The decimal value to convert. As PHP's integer type is signed, but dechex() deals with unsigned integers, negative integers will be treated as though they were unsigned.
| Negative Decimal | Positive Decimal | Hexadecimal |
|---|---|---|
| 0 | 0 | |
| 1 | 1 | |
| 2 | 2 | |
| ... | ... | |
| 9223372036854775806 | 7ffffffffffffffe | |
| 9223372036854775807 (largest signed integer) | 7fffffffffffffff | |
| -9223372036854775808 | 9223372036854775808 | 8000000000000000 |
| ... | ... | ... |
| -2 | 18446744073709551614 | fffffffffffffffe |
| -1 | 18446744073709551615 (largest unsigned integer) | ffffffffffffffff |
Return
Hexadecimal string representation of num.
Examples
1
<? $num = 0; $return = dechex($num); echo $return;
0
2
<? $num = 1; $return = dechex($num); echo $return;
1
3
<? $num = 2; $return = dechex($num); echo $return;
2
4
<? $num = 9223372036854775806; $return = dechex($num); echo $return;
7ffffffffffffffe
5
<? $num = 9223372036854775807; $return = dechex($num); echo $return;
7fffffffffffffff
6
<? $num1 = -9223372036854775808; $num2 = 9223372036854775808; $return1 = dechex($num1); $return2 = dechex($num2); echo $return1 . PHP_EOL . $return2;
7
<? $num1 = -2; $num2 = 18446744073709551614; $return1 = dechex($num1); $return2 = dechex($num2); echo $return1 . PHP_EOL . $return2;
8
<? $num1 = -1; $num2 = 18446744073709551615; $return1 = dechex($num1); $return2 = dechex($num2); echo $return1 . PHP_EOL . $return2;