Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript's .toString(16) in PHP

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.

like image 266
leonsaysHi Avatar asked Jul 24 '12 23:07

leonsaysHi


People also ask

What is toString 2 JavaScript?

toString(2) converts to binary, the tilde ( ~ ) is a bitwise unary operator stackoverflow.com/questions/791328/…

How to use toString method in JavaScript?

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.


1 Answers

Use PHP's built-in function base_convert() or dechex():

$hex = dechex(12321313); // bc0221
$hex = base_convert(4353454654, 10, 16); // 37c723e
like image 57
Crozin Avatar answered Sep 25 '22 00:09

Crozin