3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function getExclusiveORValue() { $args = func_get_args(); $ret = 0; foreach ($args as $arg) { assert('($arg >= 0) && ($arg < PHP_INT_SIZE*8)'); $ret |= 1 << $arg; } return $ret; } function getArrayOfItemsFromExclusiveORValue($bits) { $arr = array(); for ($i=0; $i<PHP_INT_SIZE*8; $i++) { $shift = $bits >> $i; if ($shift & 1) { $arr[] = $i; } if ($shift == 0) { break; } } return $arr; } $bits = getExclusiveORValue(0, 1, 3, 8, 31); echo decbin($bits) . PHP_EOL; // 10000000000000000000000100001011 $arr = getArrayOfItemsFromExclusiveORValue($bits); print_r($arr); /** Array ( [0] => 0 [1] => 1 [2] => 3 [3] => 8 [4] => 31 ) **/
Output for 4.4.0 - 4.4.9, 5.0.5 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
10000000000000000000000100001011 Array ( [0] => 0 [1] => 1 [2] => 3 [3] => 8 [4] => 31 )
Output for 4.3.10 - 4.3.11, 5.0.2 - 5.0.4
Notice: Use of undefined constant PHP_INT_SIZE - assumed 'PHP_INT_SIZE' in /in/AQUV7(8) : assert code on line 1 Warning: assert(): Assertion "($arg >= 0) && ($arg < PHP_INT_SIZE*8)" failed in /in/AQUV7 on line 8 Notice: Use of undefined constant PHP_INT_SIZE - assumed 'PHP_INT_SIZE' in /in/AQUV7(8) : assert code on line 1 Warning: assert(): Assertion "($arg >= 0) && ($arg < PHP_INT_SIZE*8)" failed in /in/AQUV7 on line 8 Notice: Use of undefined constant PHP_INT_SIZE - assumed 'PHP_INT_SIZE' in /in/AQUV7(8) : assert code on line 1 Warning: assert(): Assertion "($arg >= 0) && ($arg < PHP_INT_SIZE*8)" failed in /in/AQUV7 on line 8 Notice: Use of undefined constant PHP_INT_SIZE - assumed 'PHP_INT_SIZE' in /in/AQUV7(8) : assert code on line 1 Warning: assert(): Assertion "($arg >= 0) && ($arg < PHP_INT_SIZE*8)" failed in /in/AQUV7 on line 8 Notice: Use of undefined constant PHP_INT_SIZE - assumed 'PHP_INT_SIZE' in /in/AQUV7(8) : assert code on line 1 Warning: assert(): Assertion "($arg >= 0) && ($arg < PHP_INT_SIZE*8)" failed in /in/AQUV7 on line 8 10000000000000000000000100001011 Notice: Use of undefined constant PHP_INT_SIZE - assumed 'PHP_INT_SIZE' in /in/AQUV7 on line 16 Array ( )
Output for 4.3.2 - 4.3.9, 5.0.0 - 5.0.1
Notice: Use of undefined constant PHP_INT_SIZE - assumed 'PHP_INT_SIZE' in /in/AQUV7(8) : assert code on line 1 Warning: assert(): Assertion "($arg >= 0) && ($arg < PHP_INT_SIZE*8)" failed in /in/AQUV7 on line 8 Notice: Use of undefined constant PHP_INT_SIZE - assumed 'PHP_INT_SIZE' in /in/AQUV7(8) : assert code on line 1 Warning: assert(): Assertion "($arg >= 0) && ($arg < PHP_INT_SIZE*8)" failed in /in/AQUV7 on line 8 Notice: Use of undefined constant PHP_INT_SIZE - assumed 'PHP_INT_SIZE' in /in/AQUV7(8) : assert code on line 1 Warning: assert(): Assertion "($arg >= 0) && ($arg < PHP_INT_SIZE*8)" failed in /in/AQUV7 on line 8 Notice: Use of undefined constant PHP_INT_SIZE - assumed 'PHP_INT_SIZE' in /in/AQUV7(8) : assert code on line 1 Warning: assert(): Assertion "($arg >= 0) && ($arg < PHP_INT_SIZE*8)" failed in /in/AQUV7 on line 8 Notice: Use of undefined constant PHP_INT_SIZE - assumed 'PHP_INT_SIZE' in /in/AQUV7(8) : assert code on line 1 Warning: assert(): Assertion "($arg >= 0) && ($arg < PHP_INT_SIZE*8)" failed in /in/AQUV7 on line 8 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/AQUV7 on line 32 10000000000000000000000100001011PHP_EOL Notice: Use of undefined constant PHP_INT_SIZE - assumed 'PHP_INT_SIZE' in /in/AQUV7 on line 16 Array ( )
Output for 4.3.0 - 4.3.1
Notice: Use of undefined constant PHP_INT_SIZE - assumed 'PHP_INT_SIZE' in /in/AQUV7(8) : assert code on line 1 Warning: assert() [http://www.php.net/function.assert]: Assertion "($arg >= 0) && ($arg < PHP_INT_SIZE*8)" failed in /in/AQUV7 on line 8 Notice: Use of undefined constant PHP_INT_SIZE - assumed 'PHP_INT_SIZE' in /in/AQUV7(8) : assert code on line 1 Warning: assert() [http://www.php.net/function.assert]: Assertion "($arg >= 0) && ($arg < PHP_INT_SIZE*8)" failed in /in/AQUV7 on line 8 Notice: Use of undefined constant PHP_INT_SIZE - assumed 'PHP_INT_SIZE' in /in/AQUV7(8) : assert code on line 1 Warning: assert() [http://www.php.net/function.assert]: Assertion "($arg >= 0) && ($arg < PHP_INT_SIZE*8)" failed in /in/AQUV7 on line 8 Notice: Use of undefined constant PHP_INT_SIZE - assumed 'PHP_INT_SIZE' in /in/AQUV7(8) : assert code on line 1 Warning: assert() [http://www.php.net/function.assert]: Assertion "($arg >= 0) && ($arg < PHP_INT_SIZE*8)" failed in /in/AQUV7 on line 8 Notice: Use of undefined constant PHP_INT_SIZE - assumed 'PHP_INT_SIZE' in /in/AQUV7(8) : assert code on line 1 Warning: assert() [http://www.php.net/function.assert]: Assertion "($arg >= 0) && ($arg < PHP_INT_SIZE*8)" failed in /in/AQUV7 on line 8 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/AQUV7 on line 32 10000000000000000000000100001011PHP_EOL Notice: Use of undefined constant PHP_INT_SIZE - assumed 'PHP_INT_SIZE' in /in/AQUV7 on line 16 Array ( )