3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $s1 = bchexdec('44e1ff2dfd8102cf7a47c21d5c9fd5701610d04953c6836596b4fe9dd2f53e3e'); $s2 = bchexdec('9a5f1c75e461d7ceb1cf3cab9013eb2dc85b6d0da8c3c6e27e3a5a5b3faa5bab'); echo bcdechex(invmod($s1, -$s2)); function invmod($a,$b) { $n=$b; $x=0; $lx=1; $y=1; $ly=0; while ($b) { $t=$b; $q=bcdiv($a,$b,0); $b=bcmod($a,$b); $a=$t; $t=$x; $x=bcsub($lx,bcmod(bcmul($q,$x),$n)); $lx=$t; $t=$y; $y=bcsub($ly,bcmod(bcmul($q,$y),$n)); $ly=$t; } if (bccomp($lx,0) == -1) $lx=bcadd($lx,$n); return $lx; } function bchexdec($hex) { if(strlen($hex) == 1) { return hexdec($hex); } else { $remain = substr($hex, 0, -1); $last = substr($hex, -1); return bcadd(bcmul(16, bchexdec($remain)), hexdec($last)); } } function bcdechex($dec) { $last = bcmod($dec, 16); $remain = bcdiv(bcsub($dec, $last), 16); if($remain == 0) { return dechex($last); } else { return bcdechex($remain).dechex($last); } }
based on tesWm
Output for 4.3.2 - 5.5.28, 5.5.31 - 5.5.33, 5.5.35 - 5.6.12, 5.6.16 - 5.6.19, 5.6.21 - 7.0.4, 7.0.6 - 7.2.6
Warning: bcdiv(): Division by zero in /in/qqi85 on line 12 Warning: bcmod(): Division by zero in /in/qqi85 on line 13 Warning: bcmod(): Division by zero in /in/qqi85 on line 15 Warning: bcmod(): Division by zero in /in/qqi85 on line 16 0
Output for 7.0.5
Fatal error: Uncaught Error: Call to undefined function bcadd() in /in/qqi85:29 Stack trace: #0 /in/qqi85(2): bchexdec('44e1ff2dfd8102c...') #1 {main} thrown in /in/qqi85 on line 29
Process exited with code 255.
Output for 5.5.29 - 5.5.30, 5.5.34, 5.6.13 - 5.6.15, 5.6.20
Fatal error: Call to undefined function bcadd() in /in/qqi85 on line 29
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Warning: bcdiv() [http://www.php.net/function.bcdiv]: Division by zero in /in/qqi85 on line 12 Warning: bcmod() [http://www.php.net/function.bcmod]: Division by zero in /in/qqi85 on line 13 Warning: bcmod() [http://www.php.net/function.bcmod]: Division by zero in /in/qqi85 on line 15 Warning: bcmod() [http://www.php.net/function.bcmod]: Division by zero in /in/qqi85 on line 16 0