3v4l.org

run code in 300+ PHP versions simultaneously
<?php function strToHex($string) { $hex=''; for ($i=0; $i < strlen($string); $i++) { $hex .= dechex(ord($string[$i])); } return $hex; } function hexToStr($hex) { $string=''; for ($i=2; $i < strlen($hex)-1; $i+=2) { $string .= chr(hexdec($hex[$i].$hex[$i+1])); } return $string; } $test = "ffff:eeee:dddd:cccc:bbbb:aaaa:9999:8888"; $testParts = explode(':', $test); $testHex = array(); foreach($testParts as $testPart){ array_push($testHex, strToHex($testPart)); } $packed = pack('nvc*', $testHex[0], $testHex[1], $testHex[2], $testHex[3], $testHex[4], $testHex[5], $testHex[6], $testHex[7]); $unpacked = unpack('nvc*', $packed); $unpackedString = array(); foreach($unpacked as $unpack){ array_push($unpackedString, $unpack); } echo implode(':', $unpackedString); ?>
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 17
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 17
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 17
2 jumps found. (Code = 77) Position 1 = 45, Position 2 = 51
Branch analysis from position: 45
2 jumps found. (Code = 78) Position 1 = 46, Position 2 = 51
Branch analysis from position: 46
1 jumps found. (Code = 42) Position 1 = 45
Branch analysis from position: 45
Branch analysis from position: 51
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 51
Branch analysis from position: 17
filename:       /in/BL19S
function name:  (null)
number of ops:  58
compiled vars:  !0 = $test, !1 = $testParts, !2 = $testHex, !3 = $testPart, !4 = $packed, !5 = $unpacked, !6 = $unpackedString, !7 = $unpack
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   ASSIGN                                                   !0, 'ffff%3Aeeee%3Adddd%3Acccc%3Abbbb%3Aaaaa%3A9999%3A8888'
   23     1        INIT_FCALL                                               'explode'
          2        SEND_VAL                                                 '%3A'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $9      
          5        ASSIGN                                                   !1, $9
   25     6        ASSIGN                                                   !2, <array>
   27     7      > FE_RESET_R                                       $12     !1, ->17
          8    > > FE_FETCH_R                                               $12, !3, ->17
   28     9    >   INIT_FCALL                                               'array_push'
         10        SEND_REF                                                 !2
         11        INIT_FCALL                                               'strtohex'
         12        SEND_VAR                                                 !3
         13        DO_FCALL                                      0  $13     
         14        SEND_VAR                                                 $13
         15        DO_ICALL                                                 
   27    16      > JMP                                                      ->8
         17    >   FE_FREE                                                  $12
   30    18        INIT_FCALL                                               'pack'
         19        SEND_VAL                                                 'nvc%2A'
         20        FETCH_DIM_R                                      ~15     !2, 0
         21        SEND_VAL                                                 ~15
         22        FETCH_DIM_R                                      ~16     !2, 1
         23        SEND_VAL                                                 ~16
         24        FETCH_DIM_R                                      ~17     !2, 2
         25        SEND_VAL                                                 ~17
         26        FETCH_DIM_R                                      ~18     !2, 3
         27        SEND_VAL                                                 ~18
         28        FETCH_DIM_R                                      ~19     !2, 4
         29        SEND_VAL                                                 ~19
         30        FETCH_DIM_R                                      ~20     !2, 5
         31        SEND_VAL                                                 ~20
         32        FETCH_DIM_R                                      ~21     !2, 6
         33        SEND_VAL                                                 ~21
         34        FETCH_DIM_R                                      ~22     !2, 7
         35        SEND_VAL                                                 ~22
         36        DO_ICALL                                         $23     
         37        ASSIGN                                                   !4, $23
   31    38        INIT_FCALL                                               'unpack'
         39        SEND_VAL                                                 'nvc%2A'
         40        SEND_VAR                                                 !4
         41        DO_ICALL                                         $25     
         42        ASSIGN                                                   !5, $25
   32    43        ASSIGN                                                   !6, <array>
   33    44      > FE_RESET_R                                       $28     !5, ->51
         45    > > FE_FETCH_R                                               $28, !7, ->51
   34    46    >   INIT_FCALL                                               'array_push'
         47        SEND_REF                                                 !6
         48        SEND_VAR                                                 !7
         49        DO_ICALL                                                 
   33    50      > JMP                                                      ->45
         51    >   FE_FREE                                                  $28
   36    52        INIT_FCALL                                               'implode'
         53        SEND_VAL                                                 '%3A'
         54        SEND_VAR                                                 !6
         55        DO_ICALL                                         $30     
         56        ECHO                                                     $30
   38    57      > RETURN                                                   1

Function strtohex:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
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 = 44) Position 1 = 16, Position 2 = 4
Branch analysis from position: 16
Branch analysis from position: 4
filename:       /in/BL19S
function name:  strToHex
number of ops:  18
compiled vars:  !0 = $string, !1 = $hex, !2 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    5     1        ASSIGN                                                   !1, ''
    6     2        ASSIGN                                                   !2, 0
          3      > JMP                                                      ->13
    8     4    >   INIT_FCALL                                               'dechex'
          5        INIT_FCALL                                               'ord'
          6        FETCH_DIM_R                                      ~5      !0, !2
          7        SEND_VAL                                                 ~5
          8        DO_ICALL                                         $6      
          9        SEND_VAR                                                 $6
         10        DO_ICALL                                         $7      
         11        ASSIGN_OP                                     8          !1, $7
    6    12        PRE_INC                                                  !2
         13    >   STRLEN                                           ~10     !0
         14        IS_SMALLER                                               !2, ~10
         15      > JMPNZ                                                    ~11, ->4
   10    16    > > RETURN                                                   !1
   11    17*     > RETURN                                                   null

End of function strtohex

Function hextostr:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
2 jumps found. (Code = 44) Position 1 = 20, Position 2 = 4
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
2 jumps found. (Code = 44) Position 1 = 20, Position 2 = 4
Branch analysis from position: 20
Branch analysis from position: 4
filename:       /in/BL19S
function name:  hexToStr
number of ops:  22
compiled vars:  !0 = $hex, !1 = $string, !2 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
   14     1        ASSIGN                                                   !1, ''
   15     2        ASSIGN                                                   !2, 2
          3      > JMP                                                      ->16
   17     4    >   INIT_FCALL                                               'chr'
          5        INIT_FCALL                                               'hexdec'
          6        FETCH_DIM_R                                      ~5      !0, !2
          7        ADD                                              ~6      !2, 1
          8        FETCH_DIM_R                                      ~7      !0, ~6
          9        CONCAT                                           ~8      ~5, ~7
         10        SEND_VAL                                                 ~8
         11        DO_ICALL                                         $9      
         12        SEND_VAR                                                 $9
         13        DO_ICALL                                         $10     
         14        ASSIGN_OP                                     8          !1, $10
   15    15        ASSIGN_OP                                     1          !2, 2
         16    >   STRLEN                                           ~13     !0
         17        SUB                                              ~14     ~13, 1
         18        IS_SMALLER                                               !2, ~14
         19      > JMPNZ                                                    ~15, ->4
   19    20    > > RETURN                                                   !1
   20    21*     > RETURN                                                   null

End of function hextostr

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
167.09 ms | 1398 KiB | 32 Q