3v4l.org

run code in 300+ PHP versions simultaneously
<?php function dechex_size($val, $size) { if ($size < 1) { error_log("Invalid value for $size"); return false; } $bits = $size << 2; if ($bits > log(PHP_INT_MAX, 2)) { return dechex($val); } $mask = 0; for ($i = 0; $i < $size; ++$i) { $mask = ($mask << 4) | 0xF; } $val &= $mask; return sprintf("%x", $val); } echo dechex_size(15,4), "\n"; // gives 000f echo dechex_size(-1,16), "\n"; // gives ffffffffffffffff echo dechex_size(-1,2), "\n"; // gives ff echo dechex_size(1025,2), "\n"; // gives ? (either 401, 01, ff, or false)
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8J7Nk
function name:  (null)
number of ops:  25
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   INIT_FCALL                                               'dechex_size'
          1        SEND_VAL                                                 15
          2        SEND_VAL                                                 4
          3        DO_FCALL                                      0  $0      
          4        ECHO                                                     $0
          5        ECHO                                                     '%0A'
   24     6        INIT_FCALL                                               'dechex_size'
          7        SEND_VAL                                                 -1
          8        SEND_VAL                                                 16
          9        DO_FCALL                                      0  $1      
         10        ECHO                                                     $1
         11        ECHO                                                     '%0A'
   25    12        INIT_FCALL                                               'dechex_size'
         13        SEND_VAL                                                 -1
         14        SEND_VAL                                                 2
         15        DO_FCALL                                      0  $2      
         16        ECHO                                                     $2
         17        ECHO                                                     '%0A'
   26    18        INIT_FCALL                                               'dechex_size'
         19        SEND_VAL                                                 1025
         20        SEND_VAL                                                 2
         21        DO_FCALL                                      0  $3      
         22        ECHO                                                     $3
         23        ECHO                                                     '%0A'
         24      > RETURN                                                   1

Function dechex_size:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 10
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 22
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
2 jumps found. (Code = 44) Position 1 = 31, Position 2 = 25
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
2 jumps found. (Code = 44) Position 1 = 31, Position 2 = 25
Branch analysis from position: 31
Branch analysis from position: 25
filename:       /in/8J7Nk
function name:  dechex_size
number of ops:  38
compiled vars:  !0 = $val, !1 = $size, !2 = $bits, !3 = $mask, !4 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    4     2        IS_SMALLER                                               !1, 1
          3      > JMPZ                                                     ~5, ->10
    5     4    >   INIT_FCALL                                               'error_log'
          5        NOP                                                      
          6        FAST_CONCAT                                      ~6      'Invalid+value+for+', !1
          7        SEND_VAL                                                 ~6
          8        DO_ICALL                                                 
    6     9      > RETURN                                                   <false>
    9    10    >   SL                                               ~8      !1, 2
         11        ASSIGN                                                   !2, ~8
   10    12        INIT_FCALL                                               'log'
         13        SEND_VAL                                                 9223372036854775807
         14        SEND_VAL                                                 2
         15        DO_ICALL                                         $10     
         16        IS_SMALLER                                               $10, !2
         17      > JMPZ                                                     ~11, ->22
   11    18    >   INIT_FCALL                                               'dechex'
         19        SEND_VAR                                                 !0
         20        DO_ICALL                                         $12     
         21      > RETURN                                                   $12
   14    22    >   ASSIGN                                                   !3, 0
   15    23        ASSIGN                                                   !4, 0
         24      > JMP                                                      ->29
   16    25    >   SL                                               ~15     !3, 4
         26        BW_OR                                            ~16     ~15, 15
         27        ASSIGN                                                   !3, ~16
   15    28        PRE_INC                                                  !4
         29    >   IS_SMALLER                                               !4, !1
         30      > JMPNZ                                                    ~19, ->25
   19    31    >   ASSIGN_OP                                    10          !0, !3
   20    32        INIT_FCALL                                               'sprintf'
         33        SEND_VAL                                                 '%25x'
         34        SEND_VAR                                                 !0
         35        DO_ICALL                                         $21     
         36      > RETURN                                                   $21
   21    37*     > RETURN                                                   null

End of function dechex_size

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
165.06 ms | 1403 KiB | 25 Q