3v4l.org

run code in 300+ PHP versions simultaneously
<?php echo sprintf("%x",getCrc16("\x08\x02\x00\x00\x01\x43\xEF\x3A", 0, 0xA001, 0)); function getCrc16($buffer, $offset, $polynom, $preset) { $preset &= 0xFFFF; $polynom &= 0xFFFF; $bufLen = strlen($buffer); $crc = $preset; for($i = 0; $i < $bufLen; $i++) { $data = ord($buffer[($i + $offset)%$bufLen]); $crc ^= $data; for ($j = 0; $j < 8; $j++) { if (($crc & 0x0001) != 0) { $crc = ($crc >> 1) ^ $polynom; } else { $crc = $crc >> 1; } } } return $crc & 0xFFFF; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/KjqHL
function name:  (null)
number of ops:  12
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   INIT_FCALL                                               'sprintf'
          1        SEND_VAL                                                 '%25x'
          2        INIT_FCALL_BY_NAME                                       'getCrc16'
          3        SEND_VAL_EX                                              '%08%02%00%00%01C%EF%3A'
          4        SEND_VAL_EX                                              0
          5        SEND_VAL_EX                                              40961
          6        SEND_VAL_EX                                              0
          7        DO_FCALL                                      0  $0      
          8        SEND_VAR                                                 $0
          9        DO_ICALL                                         $1      
         10        ECHO                                                     $1
   24    11      > RETURN                                                   1

Function getcrc16:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
2 jumps found. (Code = 44) Position 1 = 36, Position 2 = 11
Branch analysis from position: 36
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
2 jumps found. (Code = 44) Position 1 = 33, Position 2 = 21
Branch analysis from position: 33
2 jumps found. (Code = 44) Position 1 = 36, Position 2 = 11
Branch analysis from position: 36
Branch analysis from position: 11
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 28
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
2 jumps found. (Code = 44) Position 1 = 33, Position 2 = 21
Branch analysis from position: 33
Branch analysis from position: 21
Branch analysis from position: 28
2 jumps found. (Code = 44) Position 1 = 33, Position 2 = 21
Branch analysis from position: 33
Branch analysis from position: 21
filename:       /in/KjqHL
function name:  getCrc16
number of ops:  39
compiled vars:  !0 = $buffer, !1 = $offset, !2 = $polynom, !3 = $preset, !4 = $bufLen, !5 = $crc, !6 = $i, !7 = $data, !8 = $j
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
    5     4        ASSIGN_OP                                    10          !3, 65535
    6     5        ASSIGN_OP                                    10          !2, 65535
    8     6        STRLEN                                           ~11     !0
          7        ASSIGN                                                   !4, ~11
   10     8        ASSIGN                                                   !5, !3
   11     9        ASSIGN                                                   !6, 0
         10      > JMP                                                      ->34
   12    11    >   INIT_FCALL                                               'ord'
         12        ADD                                              ~15     !6, !1
         13        MOD                                              ~16     ~15, !4
         14        FETCH_DIM_R                                      ~17     !0, ~16
         15        SEND_VAL                                                 ~17
         16        DO_ICALL                                         $18     
         17        ASSIGN                                                   !7, $18
   13    18        ASSIGN_OP                                    11          !5, !7
   14    19        ASSIGN                                                   !8, 0
         20      > JMP                                                      ->31
   15    21    >   BW_AND                                           ~22     !5, 1
         22        IS_NOT_EQUAL                                             ~22, 0
         23      > JMPZ                                                     ~23, ->28
   16    24    >   SR                                               ~24     !5, 1
         25        BW_XOR                                           ~25     !2, ~24
         26        ASSIGN                                                   !5, ~25
         27      > JMP                                                      ->30
   18    28    >   SR                                               ~27     !5, 1
         29        ASSIGN                                                   !5, ~27
   14    30    >   PRE_INC                                                  !8
         31    >   IS_SMALLER                                               !8, 8
         32      > JMPNZ                                                    ~30, ->21
   11    33    >   PRE_INC                                                  !6
         34    >   IS_SMALLER                                               !6, !4
         35      > JMPNZ                                                    ~32, ->11
   23    36    >   BW_AND                                           ~33     !5, 65535
         37      > RETURN                                                   ~33
   24    38*     > RETURN                                                   null

End of function getcrc16

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.57 ms | 1405 KiB | 17 Q