3v4l.org

run code in 300+ PHP versions simultaneously
<?php function string_shift_left($input, $inputlen, $bits, &$output = null) { $skip = (int) ($bits / 8); $copylen = (int) ($inputlen - $skip); $offset = ($bits % 8) & 0xff; $mask = ~(0xff >> $offset) & 0xff; $output = str_pad('', $inputlen + 1, "\x00"); echo "$skip $copylen $offset $mask\n"; if ($offset == 0) { /* Shifting multiples of 8 allows us to simply copy the relevant bytes */ for ($i = 0; $i < $copylen; $i++) { $output[$i] = $input[$i + $skip]; } return; } for ($i = 0; $i < $copylen; $i++) { $left = (ord($input[$i + $skip]) << $offset) & 0xff; $right = (ord($input[$i + $skip + 1]) & $mask) >> $offset; printf("%08b %08b\n", $left, $right); $output[$i] = chr(($left | $right) & 0xff); } } //0b000100010001000100000000; $input = "abc\x00"; $bits = 2; string_shift_left($input, strlen($input) - 1, $bits, $output); for ($i = 0; $i < strlen($input); $i++) { printf("\n%02x: %08b", ord($input[$i]), ord($input[$i])); } for ($i = 0; $i < strlen($output); $i++) { printf("\n%02x: %08b", ord($output[$i]), ord($output[$i])); }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
2 jumps found. (Code = 44) Position 1 = 29, Position 2 = 12
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 45
Branch analysis from position: 45
2 jumps found. (Code = 44) Position 1 = 48, Position 2 = 31
Branch analysis from position: 48
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 31
2 jumps found. (Code = 44) Position 1 = 48, Position 2 = 31
Branch analysis from position: 48
Branch analysis from position: 31
Branch analysis from position: 12
2 jumps found. (Code = 44) Position 1 = 29, Position 2 = 12
Branch analysis from position: 29
Branch analysis from position: 12
filename:       /in/lVhuO
function name:  (null)
number of ops:  49
compiled vars:  !0 = $input, !1 = $bits, !2 = $output, !3 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   ASSIGN                                                   !0, 'abc%00'
   32     1        ASSIGN                                                   !1, 2
   34     2        INIT_FCALL                                               'string_shift_left'
          3        SEND_VAR                                                 !0
          4        STRLEN                                           ~6      !0
          5        SUB                                              ~7      ~6, 1
          6        SEND_VAL                                                 ~7
          7        SEND_VAR                                                 !1
          8        SEND_REF                                                 !2
          9        DO_FCALL                                      0          
   36    10        ASSIGN                                                   !3, 0
         11      > JMP                                                      ->26
   37    12    >   INIT_FCALL                                               'printf'
         13        SEND_VAL                                                 '%0A%2502x%3A+%2508b'
         14        INIT_FCALL                                               'ord'
         15        FETCH_DIM_R                                      ~10     !0, !3
         16        SEND_VAL                                                 ~10
         17        DO_ICALL                                         $11     
         18        SEND_VAR                                                 $11
         19        INIT_FCALL                                               'ord'
         20        FETCH_DIM_R                                      ~12     !0, !3
         21        SEND_VAL                                                 ~12
         22        DO_ICALL                                         $13     
         23        SEND_VAR                                                 $13
         24        DO_ICALL                                                 
   36    25        PRE_INC                                                  !3
         26    >   STRLEN                                           ~16     !0
         27        IS_SMALLER                                               !3, ~16
         28      > JMPNZ                                                    ~17, ->12
   39    29    >   ASSIGN                                                   !3, 0
         30      > JMP                                                      ->45
   40    31    >   INIT_FCALL                                               'printf'
         32        SEND_VAL                                                 '%0A%2502x%3A+%2508b'
         33        INIT_FCALL                                               'ord'
         34        FETCH_DIM_R                                      ~19     !2, !3
         35        SEND_VAL                                                 ~19
         36        DO_ICALL                                         $20     
         37        SEND_VAR                                                 $20
         38        INIT_FCALL                                               'ord'
         39        FETCH_DIM_R                                      ~21     !2, !3
         40        SEND_VAL                                                 ~21
         41        DO_ICALL                                         $22     
         42        SEND_VAR                                                 $22
         43        DO_ICALL                                                 
   39    44        PRE_INC                                                  !3
         45    >   STRLEN                                           ~25     !2
         46        IS_SMALLER                                               !3, ~25
         47      > JMPNZ                                                    ~26, ->31
   41    48    > > RETURN                                                   1

Function string_shift_left:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 35, Position 2 = 45
Branch analysis from position: 35
1 jumps found. (Code = 42) Position 1 = 42
Branch analysis from position: 42
2 jumps found. (Code = 44) Position 1 = 44, Position 2 = 37
Branch analysis from position: 44
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 37
2 jumps found. (Code = 44) Position 1 = 44, Position 2 = 37
Branch analysis from position: 44
Branch analysis from position: 37
Branch analysis from position: 45
1 jumps found. (Code = 42) Position 1 = 77
Branch analysis from position: 77
2 jumps found. (Code = 44) Position 1 = 79, Position 2 = 47
Branch analysis from position: 79
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 47
2 jumps found. (Code = 44) Position 1 = 79, Position 2 = 47
Branch analysis from position: 79
Branch analysis from position: 47
filename:       /in/lVhuO
function name:  string_shift_left
number of ops:  80
compiled vars:  !0 = $input, !1 = $inputlen, !2 = $bits, !3 = $output, !4 = $skip, !5 = $copylen, !6 = $offset, !7 = $mask, !8 = $i, !9 = $left, !10 = $right
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV_INIT                                        !3      null
    5     4        DIV                                              ~11     !2, 8
          5        CAST                                          4  ~12     ~11
          6        ASSIGN                                                   !4, ~12
    6     7        SUB                                              ~14     !1, !4
          8        CAST                                          4  ~15     ~14
          9        ASSIGN                                                   !5, ~15
    7    10        MOD                                              ~17     !2, 8
         11        BW_AND                                           ~18     ~17, 255
         12        ASSIGN                                                   !6, ~18
    8    13        SR                                               ~20     255, !6
         14        BW_NOT                                           ~21     ~20
         15        BW_AND                                           ~22     ~21, 255
         16        ASSIGN                                                   !7, ~22
   10    17        INIT_FCALL                                               'str_pad'
         18        SEND_VAL                                                 ''
         19        ADD                                              ~24     !1, 1
         20        SEND_VAL                                                 ~24
         21        SEND_VAL                                                 '%00'
         22        DO_ICALL                                         $25     
         23        ASSIGN                                                   !3, $25
   12    24        ROPE_INIT                                     8  ~28     !4
         25        ROPE_ADD                                      1  ~28     ~28, '+'
         26        ROPE_ADD                                      2  ~28     ~28, !5
         27        ROPE_ADD                                      3  ~28     ~28, '+'
         28        ROPE_ADD                                      4  ~28     ~28, !6
         29        ROPE_ADD                                      5  ~28     ~28, '+'
         30        ROPE_ADD                                      6  ~28     ~28, !7
         31        ROPE_END                                      7  ~27     ~28, '%0A'
         32        ECHO                                                     ~27
   14    33        IS_EQUAL                                                 !6, 0
         34      > JMPZ                                                     ~32, ->45
   16    35    >   ASSIGN                                                   !8, 0
         36      > JMP                                                      ->42
   17    37    >   ADD                                              ~35     !8, !4
         38        FETCH_DIM_R                                      ~36     !0, ~35
         39        ASSIGN_DIM                                               !3, !8
         40        OP_DATA                                                  ~36
   16    41        PRE_INC                                                  !8
         42    >   IS_SMALLER                                               !8, !5
         43      > JMPNZ                                                    ~38, ->37
   19    44    > > RETURN                                                   null
   22    45    >   ASSIGN                                                   !8, 0
         46      > JMP                                                      ->77
   23    47    >   INIT_FCALL                                               'ord'
         48        ADD                                              ~40     !8, !4
         49        FETCH_DIM_R                                      ~41     !0, ~40
         50        SEND_VAL                                                 ~41
         51        DO_ICALL                                         $42     
         52        SL                                               ~43     $42, !6
         53        BW_AND                                           ~44     ~43, 255
         54        ASSIGN                                                   !9, ~44
   24    55        INIT_FCALL                                               'ord'
         56        ADD                                              ~46     !8, !4
         57        ADD                                              ~47     ~46, 1
         58        FETCH_DIM_R                                      ~48     !0, ~47
         59        SEND_VAL                                                 ~48
         60        DO_ICALL                                         $49     
         61        BW_AND                                           ~50     !7, $49
         62        SR                                               ~51     ~50, !6
         63        ASSIGN                                                   !10, ~51
   25    64        INIT_FCALL                                               'printf'
         65        SEND_VAL                                                 '%2508b+%2508b%0A'
         66        SEND_VAR                                                 !9
         67        SEND_VAR                                                 !10
         68        DO_ICALL                                                 
   26    69        INIT_FCALL                                               'chr'
         70        BW_OR                                            ~55     !9, !10
         71        BW_AND                                           ~56     ~55, 255
         72        SEND_VAL                                                 ~56
         73        DO_ICALL                                         $57     
         74        ASSIGN_DIM                                               !3, !8
         75        OP_DATA                                                  $57
   22    76        PRE_INC                                                  !8
         77    >   IS_SMALLER                                               !8, !5
         78      > JMPNZ                                                    ~59, ->47
   28    79    > > RETURN                                                   null

End of function string_shift_left

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
159.82 ms | 1402 KiB | 22 Q