3v4l.org

run code in 300+ PHP versions simultaneously
<?php $KEY_BASE = str_split("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"); $BASE = 62; $num = '11112887'; //$num = intval($num); //$num = array_map('intval',str_split($num)); $result = ''; $remainder = 0; /* foreach ($num as $digit) { $remainder = $digit%$BASE; echo 'remainder '.$remainder; echo 'key remainder '.$KEY_BASE[$remainder]; $result.=$KEY_BASE[$remainder]; //echo $digit; }*/ //echo $result; echo convBase($num,'0123456789','0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'); function convBase($numberInput, $fromBaseInput, $toBaseInput) { if ($fromBaseInput==$toBaseInput) return $numberInput; $fromBase = str_split($fromBaseInput,1); $toBase = str_split($toBaseInput,1); $number = str_split($numberInput,1); $fromLen=strlen($fromBaseInput); $toLen=strlen($toBaseInput); $numberLen=strlen($numberInput); $retval=''; if ($toBaseInput == '0123456789') { $retval=0; for ($i = 1;$i <= $numberLen; $i++) $retval = bcadd($retval, bcmul(array_search($number[$i-1], $fromBase),bcpow($fromLen,$numberLen-$i))); return $retval; } if ($fromBaseInput != '0123456789') $base10=convBase($numberInput, $fromBaseInput, '0123456789'); else $base10 = $numberInput; if ($base10<strlen($toBaseInput)) return $toBase[$base10]; while($base10 != '0') { $retval = $toBase[bcmod($base10,$toLen)].$retval; $base10 = bcdiv($base10,$toLen,0); } return $retval; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/cbarR
function name:  (null)
number of ops:  15
compiled vars:  !0 = $KEY_BASE, !1 = $BASE, !2 = $num, !3 = $result, !4 = $remainder
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   INIT_FCALL                                               'str_split'
          1        SEND_VAL                                                 '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
          2        DO_ICALL                                         $5      
          3        ASSIGN                                                   !0, $5
    4     4        ASSIGN                                                   !1, 62
    5     5        ASSIGN                                                   !2, '11112887'
    8     6        ASSIGN                                                   !3, ''
    9     7        ASSIGN                                                   !4, 0
   19     8        INIT_FCALL_BY_NAME                                       'convBase'
          9        SEND_VAR_EX                                              !2
         10        SEND_VAL_EX                                              '0123456789'
         11        SEND_VAL_EX                                              '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
         12        DO_FCALL                                      0  $11     
         13        ECHO                                                     $11
   50    14      > RETURN                                                   1

Function convbase:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 6
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 30, Position 2 = 57
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 54
Branch analysis from position: 54
2 jumps found. (Code = 44) Position 1 = 56, Position 2 = 33
Branch analysis from position: 56
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 33
2 jumps found. (Code = 44) Position 1 = 56, Position 2 = 33
Branch analysis from position: 56
Branch analysis from position: 33
Branch analysis from position: 57
2 jumps found. (Code = 43) Position 1 = 59, Position 2 = 66
Branch analysis from position: 59
1 jumps found. (Code = 42) Position 1 = 67
Branch analysis from position: 67
2 jumps found. (Code = 43) Position 1 = 70, Position 2 = 72
Branch analysis from position: 70
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 72
1 jumps found. (Code = 42) Position 1 = 86
Branch analysis from position: 86
2 jumps found. (Code = 44) Position 1 = 88, Position 2 = 73
Branch analysis from position: 88
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 73
2 jumps found. (Code = 44) Position 1 = 88, Position 2 = 73
Branch analysis from position: 88
Branch analysis from position: 73
Branch analysis from position: 66
2 jumps found. (Code = 43) Position 1 = 70, Position 2 = 72
Branch analysis from position: 70
Branch analysis from position: 72
filename:       /in/cbarR
function name:  convBase
number of ops:  90
compiled vars:  !0 = $numberInput, !1 = $fromBaseInput, !2 = $toBaseInput, !3 = $fromBase, !4 = $toBase, !5 = $number, !6 = $fromLen, !7 = $toLen, !8 = $numberLen, !9 = $retval, !10 = $i, !11 = $base10
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   23     3        IS_EQUAL                                                 !1, !2
          4      > JMPZ                                                     ~12, ->6
          5    > > RETURN                                                   !0
   24     6    >   INIT_FCALL                                               'str_split'
          7        SEND_VAR                                                 !1
          8        SEND_VAL                                                 1
          9        DO_ICALL                                         $13     
         10        ASSIGN                                                   !3, $13
   25    11        INIT_FCALL                                               'str_split'
         12        SEND_VAR                                                 !2
         13        SEND_VAL                                                 1
         14        DO_ICALL                                         $15     
         15        ASSIGN                                                   !4, $15
   26    16        INIT_FCALL                                               'str_split'
         17        SEND_VAR                                                 !0
         18        SEND_VAL                                                 1
         19        DO_ICALL                                         $17     
         20        ASSIGN                                                   !5, $17
   27    21        STRLEN                                           ~19     !1
         22        ASSIGN                                                   !6, ~19
   28    23        STRLEN                                           ~21     !2
         24        ASSIGN                                                   !7, ~21
   29    25        STRLEN                                           ~23     !0
         26        ASSIGN                                                   !8, ~23
   30    27        ASSIGN                                                   !9, ''
   31    28        IS_EQUAL                                                 !2, '0123456789'
         29      > JMPZ                                                     ~26, ->57
   33    30    >   ASSIGN                                                   !9, 0
   34    31        ASSIGN                                                   !10, 1
         32      > JMP                                                      ->54
   35    33    >   INIT_FCALL_BY_NAME                                       'bcadd'
         34        SEND_VAR_EX                                              !9
         35        INIT_FCALL_BY_NAME                                       'bcmul'
         36        INIT_FCALL                                               'array_search'
         37        SUB                                              ~29     !10, 1
         38        FETCH_DIM_R                                      ~30     !5, ~29
         39        SEND_VAL                                                 ~30
         40        SEND_VAR                                                 !3
         41        DO_ICALL                                         $31     
         42        SEND_VAR_NO_REF_EX                                       $31
         43        INIT_FCALL_BY_NAME                                       'bcpow'
         44        SEND_VAR_EX                                              !6
         45        SUB                                              ~32     !8, !10
         46        SEND_VAL_EX                                              ~32
         47        DO_FCALL                                      0  $33     
         48        SEND_VAR_NO_REF_EX                                       $33
         49        DO_FCALL                                      0  $34     
         50        SEND_VAR_NO_REF_EX                                       $34
         51        DO_FCALL                                      0  $35     
         52        ASSIGN                                                   !9, $35
   34    53        PRE_INC                                                  !10
         54    >   IS_SMALLER_OR_EQUAL                                      !10, !8
         55      > JMPNZ                                                    ~38, ->33
   36    56    > > RETURN                                                   !9
   38    57    >   IS_NOT_EQUAL                                             !1, '0123456789'
         58      > JMPZ                                                     ~39, ->66
   39    59    >   INIT_FCALL_BY_NAME                                       'convBase'
         60        SEND_VAR_EX                                              !0
         61        SEND_VAR_EX                                              !1
         62        SEND_VAL_EX                                              '0123456789'
         63        DO_FCALL                                      0  $40     
         64        ASSIGN                                                   !11, $40
         65      > JMP                                                      ->67
   41    66    >   ASSIGN                                                   !11, !0
   42    67    >   STRLEN                                           ~43     !2
         68        IS_SMALLER                                               !11, ~43
         69      > JMPZ                                                     ~44, ->72
   43    70    >   FETCH_DIM_R                                      ~45     !4, !11
         71      > RETURN                                                   ~45
   44    72    > > JMP                                                      ->86
   46    73    >   INIT_FCALL_BY_NAME                                       'bcmod'
         74        SEND_VAR_EX                                              !11
         75        SEND_VAR_EX                                              !7
         76        DO_FCALL                                      0  $46     
         77        FETCH_DIM_R                                      ~47     !4, $46
         78        CONCAT                                           ~48     ~47, !9
         79        ASSIGN                                                   !9, ~48
   47    80        INIT_FCALL_BY_NAME                                       'bcdiv'
         81        SEND_VAR_EX                                              !11
         82        SEND_VAR_EX                                              !7
         83        SEND_VAL_EX                                              0
         84        DO_FCALL                                      0  $50     
         85        ASSIGN                                                   !11, $50
   44    86    >   IS_NOT_EQUAL                                             !11, '0'
         87      > JMPNZ                                                    ~52, ->73
   49    88    > > RETURN                                                   !9
   50    89*     > RETURN                                                   null

End of function convbase

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
172.52 ms | 1396 KiB | 32 Q