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.
toString(2) converts to binary, the tilde ( ~ ) is a bitwise unary operator stackoverflow.com/questions/791328/…
The toString() method in Javascript is used with a number and converts the number to a string. It is used to return a string representing the specified Number object. The toString() method is used with a number num as shown in the above syntax using the '. ' operator.
Use PHP's built-in function base_convert()
or dechex()
:
$hex = dechex(12321313); // bc0221
$hex = base_convert(4353454654, 10, 16); // 37c723e
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With