3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class parentUserId { private $parentId = ''; function __construct($childid) { // convert given long int into binary it must be 64 bit long $binary = $this->dec2bin_long($childid); //trim first 16 char $binary = substr($binary, 0, 16); //add '0' in the right side upto string length get 64 $binary = str_pad($binary, 64, 0, STR_PAD_RIGHT); //Convet new binary into decimal $this->parentId = $this->bin2dec_long($binary); } public function getParentId() { return $this->parentId; } private function dec2bin_long($decimal_i) { bcscale(0); $binary_i = ''; do { $binary_i = bcmod($decimal_i, '2') . $binary_i; $decimal_i = bcdiv($decimal_i, '2'); } while (bccomp($decimal_i, '0')); return str_pad($binary_i, 64, 0, STR_PAD_LEFT); } private function bin2dec_long($binary_i) { bcscale(0); $decimal_i = '0'; for ($i = 0; $i < strlen($binary_i); $i++) { $decimal_i = bcmul($decimal_i, '2'); $decimal_i = bcadd($decimal_i, $binary_i[$i]); } return($decimal_i); } } $obj = new parentUserId("4335559066275177789"); echo $obj->getParentId(); ?>
based on Mf2io
Output for 5.3.19 - 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.0
4335559066274234368
Output for 7.0.5
Fatal error: Uncaught Error: Call to undefined function bcscale() in /in/jgpE3:23 Stack trace: #0 /in/jgpE3(9): parentUserId->dec2bin_long('433555906627517...') #1 /in/jgpE3(45): parentUserId->__construct('433555906627517...') #2 {main} thrown in /in/jgpE3 on line 23
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 bcscale() in /in/jgpE3 on line 23
Process exited with code 255.