3v4l.org

run code in 300+ PHP versions simultaneously
<?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 ) **/
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AQUV7
function name:  (null)
number of ops:  21
compiled vars:  !0 = $bits, !1 = $arr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   INIT_FCALL                                               'getexclusiveorvalue'
          1        SEND_VAL                                                 0
          2        SEND_VAL                                                 1
          3        SEND_VAL                                                 3
          4        SEND_VAL                                                 8
          5        SEND_VAL                                                 31
          6        DO_FCALL                                      0  $2      
          7        ASSIGN                                                   !0, $2
   32     8        INIT_FCALL                                               'decbin'
          9        SEND_VAR                                                 !0
         10        DO_ICALL                                         $4      
         11        CONCAT                                           ~5      $4, '%0A'
         12        ECHO                                                     ~5
   35    13        INIT_FCALL                                               'getarrayofitemsfromexclusiveorvalue'
         14        SEND_VAR                                                 !0
         15        DO_FCALL                                      0  $6      
         16        ASSIGN                                                   !1, $6
   37    17        INIT_FCALL                                               'print_r'
         18        SEND_VAR                                                 !1
         19        DO_ICALL                                                 
   47    20      > RETURN                                                   1

Function getexclusiveorvalue:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 13
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 13
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
filename:       /in/AQUV7
function name:  getExclusiveORValue
number of ops:  16
compiled vars:  !0 = $args, !1 = $ret, !2 = $arg
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   FUNC_GET_ARGS                                    ~3      
          1        ASSIGN                                                   !0, ~3
    5     2        ASSIGN                                                   !1, 0
    6     3      > FE_RESET_R                                       $6      !0, ->13
          4    > > FE_FETCH_R                                               $6, !2, ->13
    8     5    >   ASSERT_CHECK                                             
          6        INIT_FCALL                                               'assert'
          7        SEND_VAL                                                 '%28%24arg+%3E%3D+0%29+%26%26+%28%24arg+%3C+PHP_INT_SIZE%2A8%29'
          8        SEND_VAL                                                 'assert%28%27%28%24arg+%3E%3D+0%29+%26%26+%28%24arg+%3C+PHP_INT_SIZE%2A8%29%27%29'
          9        DO_ICALL                                                 
    9    10        SL                                               ~8      1, !2
         11        ASSIGN_OP                                     9          !1, ~8
    6    12      > JMP                                                      ->4
         13    >   FE_FREE                                                  $6
   11    14      > RETURN                                                   !1
   12    15*     > RETURN                                                   null

End of function getexclusiveorvalue

Function getarrayofitemsfromexclusiveorvalue:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
2 jumps found. (Code = 44) Position 1 = 16, Position 2 = 4
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 10
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 13
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
Branch analysis from position: 13
2 jumps found. (Code = 44) Position 1 = 16, Position 2 = 4
Branch analysis from position: 16
Branch analysis from position: 4
Branch analysis from position: 10
filename:       /in/AQUV7
function name:  getArrayOfItemsFromExclusiveORValue
number of ops:  18
compiled vars:  !0 = $bits, !1 = $arr, !2 = $i, !3 = $shift
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
   15     1        ASSIGN                                                   !1, <array>
   16     2        ASSIGN                                                   !2, 0
          3      > JMP                                                      ->14
   18     4    >   SR                                               ~6      !0, !2
          5        ASSIGN                                                   !3, ~6
   19     6        BW_AND                                           ~8      !3, 1
          7      > JMPZ                                                     ~8, ->10
   21     8    >   ASSIGN_DIM                                               !1
          9        OP_DATA                                                  !2
   23    10    >   IS_EQUAL                                                 !3, 0
         11      > JMPZ                                                     ~10, ->13
   25    12    > > JMP                                                      ->16
   16    13    >   PRE_INC                                                  !2
         14    >   IS_SMALLER                                               !2, 64
         15      > JMPNZ                                                    ~12, ->4
   28    16    > > RETURN                                                   !1
   29    17*     > RETURN                                                   null

End of function getarrayofitemsfromexclusiveorvalue

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
158.78 ms | 1403 KiB | 21 Q