3v4l.org

run code in 300+ PHP versions simultaneously
<?php function roundup(int $v, int $p2): int { /* purely bitwise way to round up */ return ($v + $p2 - 1) & ~($p2 - 1); } function foreach_chunk(string $s, int $chunk, callable $func): void { /* make sure the chunk length is a power of 2 */ assert($chunk & ($chunk - 1) === 0); /* iterate over each chunk and call the callback */ array_walk(str_split(str_pad($s, roundup(strlen($s), $chunk), '0', STR_PAD_LEFT), $chunk), $func); } function bytesToBits(string $bytestring) { $bitstring = ''; foreach_chunk($bytestring, 4, function (string $chunk) use (&$bitstring) { $bitstring .= str_pad(base_convert(unpack('H*', $chunk)[1], 16, 2), strlen($chunk) * 8, '0', STR_PAD_LEFT); }); return $bitstring; } function bitsToBytes(string $bitstring) { $bytestring = ''; foreach_chunk($bitstring, 32, function(string $chunk) use (&$bytestring) { $bytestring .= pack('H*', str_pad(base_convert($chunk, 2, 16), strlen($chunk) / 8, '0', STR_PAD_LEFT)); }); return $bytestring; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nlqTP
function name:  (null)
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E > > RETURN                                                   1

Function roundup:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nlqTP
function name:  roundup
number of ops:  11
compiled vars:  !0 = $v, !1 = $p2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    6     2        ADD                                              ~2      !0, !1
          3        SUB                                              ~3      ~2, 1
          4        SUB                                              ~4      !1, 1
          5        BW_NOT                                           ~5      ~4
          6        BW_AND                                           ~6      ~3, ~5
          7        VERIFY_RETURN_TYPE                                       ~6
          8      > RETURN                                                   ~6
    7     9*       VERIFY_RETURN_TYPE                                       
         10*     > RETURN                                                   null

End of function roundup

Function foreach_chunk:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nlqTP
function name:  foreach_chunk
number of ops:  31
compiled vars:  !0 = $s, !1 = $chunk, !2 = $func
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   12     3        ASSERT_CHECK                                             
          4        INIT_FCALL                                               'assert'
          5        SUB                                              ~3      !1, 1
          6        IS_IDENTICAL                                     ~4      ~3, 0
          7        BW_AND                                           ~5      !1, ~4
          8        SEND_VAL                                                 ~5
          9        SEND_VAL                                                 'assert%28%24chunk+%26+%24chunk+-+1+%3D%3D%3D+0%29'
         10        DO_ICALL                                                 
   15    11        INIT_FCALL                                               'array_walk'
         12        INIT_FCALL                                               'str_split'
         13        INIT_FCALL                                               'str_pad'
         14        SEND_VAR                                                 !0
         15        INIT_FCALL                                               'roundup'
         16        STRLEN                                           ~7      !0
         17        SEND_VAL                                                 ~7
         18        SEND_VAR                                                 !1
         19        DO_FCALL                                      0  $8      
         20        SEND_VAR                                                 $8
         21        SEND_VAL                                                 '0'
         22        SEND_VAL                                                 0
         23        DO_ICALL                                         $9      
         24        SEND_VAR                                                 $9
         25        SEND_VAR                                                 !1
         26        DO_ICALL                                         $10     
         27        SEND_VAR_NO_REF                               0          $10
         28        SEND_VAR                                                 !2
         29        DO_ICALL                                                 
   16    30      > RETURN                                                   null

End of function foreach_chunk

Function bytestobits:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nlqTP
function name:  bytesToBits
number of ops:  11
compiled vars:  !0 = $bytestring, !1 = $bitstring
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
   19     1        ASSIGN                                                   !1, ''
   21     2        INIT_FCALL                                               'foreach_chunk'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 4
          5        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FnlqTP%3A21%240'
          6        BIND_LEXICAL                                             ~3, !1
   23     7        SEND_VAL                                                 ~3
          8        DO_FCALL                                      0          
   25     9      > RETURN                                                   !1
   26    10*     > RETURN                                                   null

End of function bytestobits

Function %00%7Bclosure%7D%2Fin%2FnlqTP%3A21%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nlqTP
function name:  {closure}
number of ops:  22
compiled vars:  !0 = $chunk, !1 = $bitstring
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   22     2        INIT_FCALL                                               'str_pad'
          3        INIT_FCALL                                               'base_convert'
          4        INIT_FCALL                                               'unpack'
          5        SEND_VAL                                                 'H%2A'
          6        SEND_VAR                                                 !0
          7        DO_ICALL                                         $2      
          8        FETCH_DIM_R                                      ~3      $2, 1
          9        SEND_VAL                                                 ~3
         10        SEND_VAL                                                 16
         11        SEND_VAL                                                 2
         12        DO_ICALL                                         $4      
         13        SEND_VAR                                                 $4
         14        STRLEN                                           ~5      !0
         15        MUL                                              ~6      ~5, 8
         16        SEND_VAL                                                 ~6
         17        SEND_VAL                                                 '0'
         18        SEND_VAL                                                 0
         19        DO_ICALL                                         $7      
         20        ASSIGN_OP                                     8          !1, $7
   23    21      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FnlqTP%3A21%240

Function bitstobytes:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nlqTP
function name:  bitsToBytes
number of ops:  11
compiled vars:  !0 = $bitstring, !1 = $bytestring
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   RECV                                             !0      
   29     1        ASSIGN                                                   !1, ''
   31     2        INIT_FCALL                                               'foreach_chunk'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 32
          5        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FnlqTP%3A31%241'
          6        BIND_LEXICAL                                             ~3, !1
   33     7        SEND_VAL                                                 ~3
          8        DO_FCALL                                      0          
   35     9      > RETURN                                                   !1
   36    10*     > RETURN                                                   null

End of function bitstobytes

Function %00%7Bclosure%7D%2Fin%2FnlqTP%3A31%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nlqTP
function name:  {closure}
number of ops:  21
compiled vars:  !0 = $chunk, !1 = $bytestring
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   32     2        INIT_FCALL                                               'pack'
          3        SEND_VAL                                                 'H%2A'
          4        INIT_FCALL                                               'str_pad'
          5        INIT_FCALL                                               'base_convert'
          6        SEND_VAR                                                 !0
          7        SEND_VAL                                                 2
          8        SEND_VAL                                                 16
          9        DO_ICALL                                         $2      
         10        SEND_VAR                                                 $2
         11        STRLEN                                           ~3      !0
         12        DIV                                              ~4      ~3, 8
         13        SEND_VAL                                                 ~4
         14        SEND_VAL                                                 '0'
         15        SEND_VAL                                                 0
         16        DO_ICALL                                         $5      
         17        SEND_VAR                                                 $5
         18        DO_ICALL                                         $6      
         19        ASSIGN_OP                                     8          !1, $6
   33    20      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FnlqTP%3A31%241

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
179.75 ms | 1411 KiB | 30 Q