I'd like to do the same as JavaScript's .toString(16)
but in PHP :
var n = 200000002713419;
console.log(n.toString(16));
This returns b5e6211de74b
.
How can I achieve the same with PHP ?
Thanks a lot.
I'd like to do the same as JavaScript's .toString(16)
but in PHP :
var n = 200000002713419;
console.log(n.toString(16));
This returns b5e6211de74b
.
How can I achieve the same with PHP ?
Thanks a lot.
Share Improve this question edited Jul 24, 2012 at 23:31 Derek 朕會功夫 94.3k45 gold badges196 silver badges253 bronze badges asked Jul 24, 2012 at 23:25 leonsaysHileonsaysHi 3752 silver badges12 bronze badges 3-
3
dechex()
will get you part of the way there, but note the limitations in the docs: php/manual/en/function.dechex.php – rjz Commented Jul 24, 2012 at 23:27 - @zerkms, I couldn't sleep with the guilt of submitting one that would fail the given usage case :^) – rjz Commented Jul 24, 2012 at 23:33
- 1 @rjz: among "good dreams" and "at least +40 rep points" I would choose the latter ;-) – zerkms Commented Jul 24, 2012 at 23:34
1 Answer
Reset to default 16Use PHP's built-in function base_convert()
or dechex()
:
$hex = dechex(12321313); // bc0221
$hex = base_convert(4353454654, 10, 16); // 37c723e