dechex
Description
Syntax
dechex ( int $number ) : string
Parameters
number
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 number.
Examples
1
<? $number = 0; $return = dechex($number); echo $return; ?>
0
2
<? $number = 1; $return = dechex($number); echo $return; ?>
1
3
<? $number = 2; $return = dechex($number); echo $return; ?>
2
4
<? $number = 9223372036854775806; $return = dechex($number); echo $return; ?>
7ffffffffffffffe
5
<? $number = 9223372036854775807; $return = dechex($number); echo $return; ?>
7fffffffffffffff
6
<? $number1 = -9223372036854775808; $number2 = 9223372036854775808; $return1 = dechex($number1); $return2 = dechex($number2); echo $return1 . PHP_EOL; echo $return2; ?>
7
<? $number1 = -2; $number2 = 18446744073709551614; $return1 = dechex($number1); $return2 = dechex($number2); echo $return1 . PHP_EOL; echo $return2; ?>
8
<? $number1 = -1; $number2 = 18446744073709551615; $return1 = dechex($number1); $return2 = dechex($number2); echo $return1 . PHP_EOL; echo $return2; ?>