3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function dec_to_hex($dec) { $sign = ""; // suppress errors if( $dec < 0){ $sign = "-"; $dec = abs($dec); } $hex = Array( 0 => 0, 1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6, 7 => 7, 8 => 8, 9 => 9, 10 => 'a', 11 => 'b', 12 => 'c', 13 => 'd', 14 => 'e', 15 => 'f' ); do { $h = $hex[($dec%16)] . $h; $dec /= 16; } while( $dec >= 1 ); return $sign . $h; } function dec2hex($number) { $number = strval($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; } $id = 14910855968770314426; var_dump($id); $guid = dec_to_hex($id); var_dump($guid);
Output for 5.0.4 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
float(1.491085596877E+19) Notice: Undefined variable: h in /in/mqu5P on line 15 string(16) "ceee0080a3915000"
Output for 4.3.0 - 5.0.1, 5.0.3
float(1.491085596877E+19) Notice: Undefined variable: h in /in/mqu5P on line 15 string(16) "ceee0080a3915000"
Output for 5.0.2
float(1.491085596877E+19) Notice: Undefined variable: h in /in/mqu5P on line 15 string(16) "ceee0080a391500f"