3v4l.org

run code in 300+ PHP versions simultaneously
<?php function toHex($n) { $n = intval($n); if (!$n) return '00'; $n = max(0, min($n, 255)); // make sure the $n is not bigger than 255 and not less than 0 $index1 = (int) ($n - ($n % 16)) / 16; $index2 = (int) $n % 16; return substr("0123456789ABCDEF", $index1, 1) . substr("0123456789ABCDEF", $index2, 1); } $r = 254; $g = 255; $b = 0; echo $hex = '#' . toHex($r) . toHex($g) . toHex($b); ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jm74g
function name:  (null)
number of ops:  18
compiled vars:  !0 = $r, !1 = $g, !2 = $b, !3 = $hex
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   ASSIGN                                                   !0, 254
          1        ASSIGN                                                   !1, 255
          2        ASSIGN                                                   !2, 0
   15     3        INIT_FCALL                                               'tohex'
          4        SEND_VAR                                                 !0
          5        DO_FCALL                                      0  $7      
          6        CONCAT                                           ~8      '%23', $7
          7        INIT_FCALL                                               'tohex'
          8        SEND_VAR                                                 !1
          9        DO_FCALL                                      0  $9      
         10        CONCAT                                           ~10     ~8, $9
         11        INIT_FCALL                                               'tohex'
         12        SEND_VAR                                                 !2
         13        DO_FCALL                                      0  $11     
         14        CONCAT                                           ~12     ~10, $11
         15        ASSIGN                                           ~13     !3, ~12
         16        ECHO                                                     ~13
   16    17      > RETURN                                                   1

Function tohex:
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
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jm74g
function name:  toHex
number of ops:  36
compiled vars:  !0 = $n, !1 = $index1, !2 = $index2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
    3     1        CAST                                          4  ~3      !0
          2        ASSIGN                                                   !0, ~3
    4     3        BOOL_NOT                                         ~5      !0
          4      > JMPZ                                                     ~5, ->6
    5     5    > > RETURN                                                   '00'
    7     6    >   INIT_FCALL                                               'max'
          7        SEND_VAL                                                 0
          8        INIT_FCALL                                               'min'
          9        SEND_VAR                                                 !0
         10        SEND_VAL                                                 255
         11        DO_ICALL                                         $6      
         12        SEND_VAR                                                 $6
         13        DO_ICALL                                         $7      
         14        ASSIGN                                                   !0, $7
    8    15        MOD                                              ~9      !0, 16
         16        SUB                                              ~10     !0, ~9
         17        CAST                                          4  ~11     ~10
         18        DIV                                              ~12     ~11, 16
         19        ASSIGN                                                   !1, ~12
    9    20        CAST                                          4  ~14     !0
         21        MOD                                              ~15     ~14, 16
         22        ASSIGN                                                   !2, ~15
   11    23        INIT_FCALL                                               'substr'
         24        SEND_VAL                                                 '0123456789ABCDEF'
         25        SEND_VAR                                                 !1
         26        SEND_VAL                                                 1
         27        DO_ICALL                                         $17     
   12    28        INIT_FCALL                                               'substr'
         29        SEND_VAL                                                 '0123456789ABCDEF'
         30        SEND_VAR                                                 !2
         31        SEND_VAL                                                 1
         32        DO_ICALL                                         $18     
         33        CONCAT                                           ~19     $17, $18
         34      > RETURN                                                   ~19
   13    35*     > RETURN                                                   null

End of function tohex

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
159.91 ms | 1403 KiB | 22 Q