You can use Math/BigInteger
to solve your problem and easily create a hexadecimal converter:
<?php
include('Math/BigInteger.php');
function toHex($n) {
$zero = new Math_BigInteger(0);
if ($n->compare($zero) == 0) return "0";
$base = "0123456789ABCDEF";
$dezesseis = new Math_BigInteger(16);
$result = "";
while ($n->compare($zero) > 0) {
list($n, $r) = $n->divide($dezesseis);
$result = $base[intval($r->toString())] . $result;
}
return $result;
}
function milliToHex() {
$temp = new Math_BigInteger(time());
$mil = new Math_BigInteger(1000);
$ret = toHex($temp->multiply($mil));
return str_pad($ret, 16, "0", STR_PAD_LEFT);
}
echo milliToHex();
?>
For me, it produced this output:
0000016468976E40
See here working on ideone (but do not be alarmed at the size of the code, as I had to copy and paste the whole Math/BigInteger
class there in the ideone).
I've already done this answer three and a half years ago using some similar concepts.