3v4l.org

run code in 300+ PHP versions simultaneously
<?php function bytesToBits(string $bytestring) : string { $parts = ''; foreach (str_split($bytestring, 4) as $chunk) { $parts .= str_pad(base_convert(unpack('H*', $chunk)[1], 16, 2), 32, '0', STR_PAD_LEFT); } return $parts; } function bitsToBytes(string $bitstring) : string { $remain = $bitstring % 32; if ($remain !== 0) { $bitstring = str_pad($bitstring, $remain, '0', STR_PAD_LEFT); } $parts = ''; foreach (str_split($bitstring, 32) as $chunk) { $parts .= pack('H*', str_pad(base_convert($chunk, 2, 16), 8, '0', STR_PAD_LEFT)); } return $parts; } for ($i = 0; $i < 100; $i++) { $bytestring_in = hash('sha512', uniqid('', true)); $bits = bytesToBits($bytestring_in); $bytestring_out = bitsToBytes($bits); if ($bytestring_in !== $bytestring_out) { die('Error in functions.'); } } echo 'All ok!' . PHP_EOL;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
2 jumps found. (Code = 44) Position 1 = 25, Position 2 = 2
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 2
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 22
Branch analysis from position: 21
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 22
2 jumps found. (Code = 44) Position 1 = 25, Position 2 = 2
Branch analysis from position: 25
Branch analysis from position: 2
filename:       /in/hilSd
function name:  (null)
number of ops:  27
compiled vars:  !0 = $i, !1 = $bytestring_in, !2 = $bits, !3 = $bytestring_out
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   ASSIGN                                                   !0, 0
          1      > JMP                                                      ->23
   24     2    >   INIT_FCALL                                               'hash'
          3        SEND_VAL                                                 'sha512'
          4        INIT_FCALL                                               'uniqid'
          5        SEND_VAL                                                 ''
          6        SEND_VAL                                                 <true>
          7        DO_ICALL                                         $5      
          8        SEND_VAR                                                 $5
          9        DO_ICALL                                         $6      
         10        ASSIGN                                                   !1, $6
   25    11        INIT_FCALL                                               'bytestobits'
         12        SEND_VAR                                                 !1
         13        DO_FCALL                                      0  $8      
         14        ASSIGN                                                   !2, $8
   26    15        INIT_FCALL                                               'bitstobytes'
         16        SEND_VAR                                                 !2
         17        DO_FCALL                                      0  $10     
         18        ASSIGN                                                   !3, $10
   27    19        IS_NOT_IDENTICAL                                         !1, !3
         20      > JMPZ                                                     ~12, ->22
   28    21    > > EXIT                                                     'Error+in+functions.'
   23    22    >   PRE_INC                                                  !0
         23    >   IS_SMALLER                                               !0, 100
         24      > JMPNZ                                                    ~14, ->2
   32    25    >   ECHO                                                     'All+ok%21%0A'
         26      > RETURN                                                   1

Function bytestobits:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 26
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 26
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
filename:       /in/hilSd
function name:  bytesToBits
number of ops:  31
compiled vars:  !0 = $bytestring, !1 = $parts, !2 = $chunk
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        ASSIGN                                                   !1, ''
    5     2        INIT_FCALL                                               'str_split'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 4
          5        DO_ICALL                                         $4      
          6      > FE_RESET_R                                       $5      $4, ->26
          7    > > FE_FETCH_R                                               $5, !2, ->26
    6     8    >   INIT_FCALL                                               'str_pad'
          9        INIT_FCALL                                               'base_convert'
         10        INIT_FCALL                                               'unpack'
         11        SEND_VAL                                                 'H%2A'
         12        SEND_VAR                                                 !2
         13        DO_ICALL                                         $6      
         14        FETCH_DIM_R                                      ~7      $6, 1
         15        SEND_VAL                                                 ~7
         16        SEND_VAL                                                 16
         17        SEND_VAL                                                 2
         18        DO_ICALL                                         $8      
         19        SEND_VAR                                                 $8
         20        SEND_VAL                                                 32
         21        SEND_VAL                                                 '0'
         22        SEND_VAL                                                 0
         23        DO_ICALL                                         $9      
         24        ASSIGN_OP                                     8          !1, $9
    5    25      > JMP                                                      ->7
         26    >   FE_FREE                                                  $5
    8    27        VERIFY_RETURN_TYPE                                       !1
         28      > RETURN                                                   !1
    9    29*       VERIFY_RETURN_TYPE                                       
         30*     > RETURN                                                   null

End of function bytestobits

Function bitstobytes:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 12
Branch analysis from position: 5
2 jumps found. (Code = 77) Position 1 = 18, Position 2 = 36
Branch analysis from position: 18
2 jumps found. (Code = 78) Position 1 = 19, Position 2 = 36
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
Branch analysis from position: 36
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 36
Branch analysis from position: 12
filename:       /in/hilSd
function name:  bitsToBytes
number of ops:  41
compiled vars:  !0 = $bitstring, !1 = $remain, !2 = $parts, !3 = $chunk
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
   12     1        MOD                                              ~4      !0, 32
          2        ASSIGN                                                   !1, ~4
   13     3        IS_NOT_IDENTICAL                                         !1, 0
          4      > JMPZ                                                     ~6, ->12
   14     5    >   INIT_FCALL                                               'str_pad'
          6        SEND_VAR                                                 !0
          7        SEND_VAR                                                 !1
          8        SEND_VAL                                                 '0'
          9        SEND_VAL                                                 0
         10        DO_ICALL                                         $7      
         11        ASSIGN                                                   !0, $7
   16    12    >   ASSIGN                                                   !2, ''
   17    13        INIT_FCALL                                               'str_split'
         14        SEND_VAR                                                 !0
         15        SEND_VAL                                                 32
         16        DO_ICALL                                         $10     
         17      > FE_RESET_R                                       $11     $10, ->36
         18    > > FE_FETCH_R                                               $11, !3, ->36
   18    19    >   INIT_FCALL                                               'pack'
         20        SEND_VAL                                                 'H%2A'
         21        INIT_FCALL                                               'str_pad'
         22        INIT_FCALL                                               'base_convert'
         23        SEND_VAR                                                 !3
         24        SEND_VAL                                                 2
         25        SEND_VAL                                                 16
         26        DO_ICALL                                         $12     
         27        SEND_VAR                                                 $12
         28        SEND_VAL                                                 8
         29        SEND_VAL                                                 '0'
         30        SEND_VAL                                                 0
         31        DO_ICALL                                         $13     
         32        SEND_VAR                                                 $13
         33        DO_ICALL                                         $14     
         34        ASSIGN_OP                                     8          !2, $14
   17    35      > JMP                                                      ->18
         36    >   FE_FREE                                                  $11
   20    37        VERIFY_RETURN_TYPE                                       !2
         38      > RETURN                                                   !2
   21    39*       VERIFY_RETURN_TYPE                                       
         40*     > RETURN                                                   null

End of function bitstobytes

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
138.8 ms | 1411 KiB | 29 Q