3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* convert 16-bit numeric string to decimal */ function showDecimal( $bin, $base ) { $num = intval( $bin, $base ); $num &= 0xffff; // using only last 16 bits if ( 0x8000 & $num ) { // true if $num is negative ... $num =( $num - 0x010000 ); } return $num; } $b = "ffffffbf"; // 2s complement (hex) for echo showDecimal($b,16),"\n"; // -65 $c = "1111111111111101"; // 2s complement (binary) for echo showDecimal($c,2),"\n"; // -3
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8M9kQ
function name:  (null)
number of ops:  15
compiled vars:  !0 = $b, !1 = $c
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   ASSIGN                                                   !0, 'ffffffbf'
   17     1        INIT_FCALL                                               'showdecimal'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 16
          4        DO_FCALL                                      0  $3      
          5        ECHO                                                     $3
          6        ECHO                                                     '%0A'
   19     7        ASSIGN                                                   !1, '1111111111111101'
   20     8        INIT_FCALL                                               'showdecimal'
          9        SEND_VAR                                                 !1
         10        SEND_VAL                                                 2
         11        DO_FCALL                                      0  $5      
         12        ECHO                                                     $5
         13        ECHO                                                     '%0A'
         14      > RETURN                                                   1

Function showdecimal:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 12
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
filename:       /in/8M9kQ
function name:  showDecimal
number of ops:  14
compiled vars:  !0 = $bin, !1 = $base, !2 = $num
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    6     2        INIT_FCALL                                               'intval'
          3        SEND_VAR                                                 !0
          4        SEND_VAR                                                 !1
          5        DO_ICALL                                         $3      
          6        ASSIGN                                                   !2, $3
    8     7        ASSIGN_OP                                    10          !2, 65535
    9     8        BW_AND                                           ~6      !2, 32768
          9      > JMPZ                                                     ~6, ->12
   10    10    >   SUB                                              ~7      !2, 65536
         11        ASSIGN                                                   !2, ~7
   13    12    > > RETURN                                                   !2
   14    13*     > RETURN                                                   null

End of function showdecimal

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
143.15 ms | 1399 KiB | 17 Q