The problem is that The largest number that can be converted is ... 4294967295 - hence why it does not work for you.
This answer worked for me during a quick test, assuming you have bcmath installed on your server , and you can get the number as a string to run from . If you cannot, that is, it starts life as a numerical variable, you will immediately reach the PHP float limit .
// Credit: joost at bingopaleis dot com // Input: A decimal number as a String. // Output: The equivalent hexadecimal number as a String. function dec2hex($number) { $hexvalues = array('0','1','2','3','4','5','6','7', '8','9','A','B','C','D','E','F'); $hexval = ''; while($number != '0') { $hexval = $hexvalues[bcmod($number,'16')].$hexval; $number = bcdiv($number,'16',0); } return $hexval; }
Example:
$number = '114483222461061018757513232564608398004'; // Important: already a string! var_dump(dec2hex($number)); // string(32) "5620AAA80D50FD70496983E2A39972B4"
Make sure you pass a string to this function, not a numeric one. In the example you pointed out in the question, it looks like you can get the number as a string first, so it should work if you have bc installed.
source share