3v4l.org

run code in 300+ PHP versions simultaneously
<?php // https://stackoverflow.com/questions/35536141/converting-binary-data-to-ascii-with-php-any-possibility/35536281#35536281 function bin2ascii($input) { $output = ''; for($i=0; $i<strlen($input); $i+=8) { $output .= chr(intval(substr($input, $i, 8), 2)); } return $output; } https://stackoverflow.com/questions/6382738/convert-string-to-binary-then-back-again-using-php/6382880#6382880 function ascii2bin($input) { return array_reduce(str_split($input), fn ($acc, $i) => $acc .= decbin(ord($i))); //return array_reduce(str_split($input), fn ($acc, $i) => $acc .= str_pad(decbin(ord($i)), 8, '0', STR_PAD_LEFT)); } $i = -114514; var_dump( decbin($i)); var_dump( ltrim(decbin($i), $i < 0 ? '1' : '0')); var_dump( ($i < 0 ? '1' : '0') . ltrim(decbin($i), $i < 0 ? '1' : '0')); var_dump( bin2ascii(($i < 0 ? '1' : '0') . ltrim(decbin($i), $i < 0 ? '1' : '0'))); $o = rtrim(base64_encode(bin2ascii(($i < 0 ? '1' : '0') . ltrim(decbin($i), $i < 0 ? '1' : '0'))), '='); var_dump($o); $d = base64_decode($o); var_dump($d); $bits = ascii2bin($d); $signBit = decbin(ord($d))[0]; $paddedBits = str_pad($bits, (strlen($bits) + (strlen($bits) % 8)) / 8, $signBit, STR_PAD_LEFT); var_dump($bits); var_dump($signBit); var_dump($paddedBits); var_dump(intval($paddedBits, 2));
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 17
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 27
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
2 jumps found. (Code = 43) Position 1 = 35, Position 2 = 37
Branch analysis from position: 35
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
2 jumps found. (Code = 43) Position 1 = 47, Position 2 = 49
Branch analysis from position: 47
1 jumps found. (Code = 42) Position 1 = 50
Branch analysis from position: 50
2 jumps found. (Code = 43) Position 1 = 57, Position 2 = 59
Branch analysis from position: 57
1 jumps found. (Code = 42) Position 1 = 60
Branch analysis from position: 60
2 jumps found. (Code = 43) Position 1 = 72, Position 2 = 74
Branch analysis from position: 72
1 jumps found. (Code = 42) Position 1 = 75
Branch analysis from position: 75
2 jumps found. (Code = 43) Position 1 = 82, Position 2 = 84
Branch analysis from position: 82
1 jumps found. (Code = 42) Position 1 = 85
Branch analysis from position: 85
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 84
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 74
2 jumps found. (Code = 43) Position 1 = 82, Position 2 = 84
Branch analysis from position: 82
Branch analysis from position: 84
Branch analysis from position: 59
2 jumps found. (Code = 43) Position 1 = 72, Position 2 = 74
Branch analysis from position: 72
Branch analysis from position: 74
Branch analysis from position: 49
2 jumps found. (Code = 43) Position 1 = 57, Position 2 = 59
Branch analysis from position: 57
Branch analysis from position: 59
Branch analysis from position: 37
2 jumps found. (Code = 43) Position 1 = 47, Position 2 = 49
Branch analysis from position: 47
Branch analysis from position: 49
Branch analysis from position: 27
2 jumps found. (Code = 43) Position 1 = 35, Position 2 = 37
Branch analysis from position: 35
Branch analysis from position: 37
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 27
Branch analysis from position: 25
Branch analysis from position: 27
filename:       /in/PiE5u
function name:  (null)
number of ops:  147
compiled vars:  !0 = $i, !1 = $o, !2 = $d, !3 = $bits, !4 = $signBit, !5 = $paddedBits
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   ASSIGN                                                   !0, -114514
   17     1        INIT_FCALL                                               'var_dump'
          2        INIT_FCALL                                               'decbin'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $7      
          5        SEND_VAR                                                 $7
          6        DO_ICALL                                                 
   18     7        INIT_FCALL                                               'var_dump'
          8        INIT_FCALL                                               'ltrim'
          9        INIT_FCALL                                               'decbin'
         10        SEND_VAR                                                 !0
         11        DO_ICALL                                         $9      
         12        SEND_VAR                                                 $9
         13        IS_SMALLER                                               !0, 0
         14      > JMPZ                                                     ~10, ->17
         15    >   QM_ASSIGN                                        ~11     '1'
         16      > JMP                                                      ->18
         17    >   QM_ASSIGN                                        ~11     '0'
         18    >   SEND_VAL                                                 ~11
         19        DO_ICALL                                         $12     
         20        SEND_VAR                                                 $12
         21        DO_ICALL                                                 
   19    22        INIT_FCALL                                               'var_dump'
         23        IS_SMALLER                                               !0, 0
         24      > JMPZ                                                     ~14, ->27
         25    >   QM_ASSIGN                                        ~15     '1'
         26      > JMP                                                      ->28
         27    >   QM_ASSIGN                                        ~15     '0'
         28    >   INIT_FCALL                                               'ltrim'
         29        INIT_FCALL                                               'decbin'
         30        SEND_VAR                                                 !0
         31        DO_ICALL                                         $16     
         32        SEND_VAR                                                 $16
         33        IS_SMALLER                                               !0, 0
         34      > JMPZ                                                     ~17, ->37
         35    >   QM_ASSIGN                                        ~18     '1'
         36      > JMP                                                      ->38
         37    >   QM_ASSIGN                                        ~18     '0'
         38    >   SEND_VAL                                                 ~18
         39        DO_ICALL                                         $19     
         40        CONCAT                                           ~20     ~15, $19
         41        SEND_VAL                                                 ~20
         42        DO_ICALL                                                 
   20    43        INIT_FCALL                                               'var_dump'
         44        INIT_FCALL                                               'bin2ascii'
         45        IS_SMALLER                                               !0, 0
         46      > JMPZ                                                     ~22, ->49
         47    >   QM_ASSIGN                                        ~23     '1'
         48      > JMP                                                      ->50
         49    >   QM_ASSIGN                                        ~23     '0'
         50    >   INIT_FCALL                                               'ltrim'
         51        INIT_FCALL                                               'decbin'
         52        SEND_VAR                                                 !0
         53        DO_ICALL                                         $24     
         54        SEND_VAR                                                 $24
         55        IS_SMALLER                                               !0, 0
         56      > JMPZ                                                     ~25, ->59
         57    >   QM_ASSIGN                                        ~26     '1'
         58      > JMP                                                      ->60
         59    >   QM_ASSIGN                                        ~26     '0'
         60    >   SEND_VAL                                                 ~26
         61        DO_ICALL                                         $27     
         62        CONCAT                                           ~28     ~23, $27
         63        SEND_VAL                                                 ~28
         64        DO_FCALL                                      0  $29     
         65        SEND_VAR                                                 $29
         66        DO_ICALL                                                 
   21    67        INIT_FCALL                                               'rtrim'
         68        INIT_FCALL                                               'base64_encode'
         69        INIT_FCALL                                               'bin2ascii'
         70        IS_SMALLER                                               !0, 0
         71      > JMPZ                                                     ~31, ->74
         72    >   QM_ASSIGN                                        ~32     '1'
         73      > JMP                                                      ->75
         74    >   QM_ASSIGN                                        ~32     '0'
         75    >   INIT_FCALL                                               'ltrim'
         76        INIT_FCALL                                               'decbin'
         77        SEND_VAR                                                 !0
         78        DO_ICALL                                         $33     
         79        SEND_VAR                                                 $33
         80        IS_SMALLER                                               !0, 0
         81      > JMPZ                                                     ~34, ->84
         82    >   QM_ASSIGN                                        ~35     '1'
         83      > JMP                                                      ->85
         84    >   QM_ASSIGN                                        ~35     '0'
         85    >   SEND_VAL                                                 ~35
         86        DO_ICALL                                         $36     
         87        CONCAT                                           ~37     ~32, $36
         88        SEND_VAL                                                 ~37
         89        DO_FCALL                                      0  $38     
         90        SEND_VAR                                                 $38
         91        DO_ICALL                                         $39     
         92        SEND_VAR                                                 $39
         93        SEND_VAL                                                 '%3D'
         94        DO_ICALL                                         $40     
         95        ASSIGN                                                   !1, $40
   22    96        INIT_FCALL                                               'var_dump'
         97        SEND_VAR                                                 !1
         98        DO_ICALL                                                 
   24    99        INIT_FCALL                                               'base64_decode'
        100        SEND_VAR                                                 !1
        101        DO_ICALL                                         $43     
        102        ASSIGN                                                   !2, $43
   25   103        INIT_FCALL                                               'var_dump'
        104        SEND_VAR                                                 !2
        105        DO_ICALL                                                 
   26   106        INIT_FCALL                                               'ascii2bin'
        107        SEND_VAR                                                 !2
        108        DO_FCALL                                      0  $46     
        109        ASSIGN                                                   !3, $46
   27   110        INIT_FCALL                                               'decbin'
        111        INIT_FCALL                                               'ord'
        112        SEND_VAR                                                 !2
        113        DO_ICALL                                         $48     
        114        SEND_VAR                                                 $48
        115        DO_ICALL                                         $49     
        116        FETCH_DIM_R                                      ~50     $49, 0
        117        ASSIGN                                                   !4, ~50
   28   118        INIT_FCALL                                               'str_pad'
        119        SEND_VAR                                                 !3
        120        STRLEN                                           ~52     !3
        121        STRLEN                                           ~53     !3
        122        MOD                                              ~54     ~53, 8
        123        ADD                                              ~55     ~52, ~54
        124        DIV                                              ~56     ~55, 8
        125        SEND_VAL                                                 ~56
        126        SEND_VAR                                                 !4
        127        SEND_VAL                                                 0
        128        DO_ICALL                                         $57     
        129        ASSIGN                                                   !5, $57
   29   130        INIT_FCALL                                               'var_dump'
        131        SEND_VAR                                                 !3
        132        DO_ICALL                                                 
   30   133        INIT_FCALL                                               'var_dump'
        134        SEND_VAR                                                 !4
        135        DO_ICALL                                                 
   31   136        INIT_FCALL                                               'var_dump'
        137        SEND_VAR                                                 !5
        138        DO_ICALL                                                 
   32   139        INIT_FCALL                                               'var_dump'
        140        INIT_FCALL                                               'intval'
        141        SEND_VAR                                                 !5
        142        SEND_VAL                                                 2
        143        DO_ICALL                                         $62     
        144        SEND_VAR                                                 $62
        145        DO_ICALL                                                 
        146      > RETURN                                                   1

Function bin2ascii:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
2 jumps found. (Code = 44) Position 1 = 21, Position 2 = 4
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
2 jumps found. (Code = 44) Position 1 = 21, Position 2 = 4
Branch analysis from position: 21
Branch analysis from position: 4
filename:       /in/PiE5u
function name:  bin2ascii
number of ops:  23
compiled vars:  !0 = $input, !1 = $output, !2 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        ASSIGN                                                   !1, ''
    5     2        ASSIGN                                                   !2, 0
          3      > JMP                                                      ->18
    6     4    >   INIT_FCALL                                               'chr'
          5        INIT_FCALL                                               'intval'
          6        INIT_FCALL                                               'substr'
          7        SEND_VAR                                                 !0
          8        SEND_VAR                                                 !2
          9        SEND_VAL                                                 8
         10        DO_ICALL                                         $5      
         11        SEND_VAR                                                 $5
         12        SEND_VAL                                                 2
         13        DO_ICALL                                         $6      
         14        SEND_VAR                                                 $6
         15        DO_ICALL                                         $7      
         16        ASSIGN_OP                                     8          !1, $7
    5    17        ASSIGN_OP                                     1          !2, 8
         18    >   STRLEN                                           ~10     !0
         19        IS_SMALLER                                               !2, ~10
         20      > JMPNZ                                                    ~11, ->4
    8    21    > > RETURN                                                   !1
    9    22*     > RETURN                                                   null

End of function bin2ascii

Function ascii2bin:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/PiE5u
function name:  ascii2bin
number of ops:  11
compiled vars:  !0 = $input
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
   12     1        INIT_FCALL                                               'array_reduce'
          2        INIT_FCALL                                               'str_split'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $1      
          5        SEND_VAR                                                 $1
          6        DECLARE_LAMBDA_FUNCTION                          ~2      [0]
          7        SEND_VAL                                                 ~2
          8        DO_ICALL                                         $3      
          9      > RETURN                                                   $3
   14    10*     > RETURN                                                   null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/PiE5u
function name:  {closure}
number of ops:  11
compiled vars:  !0 = $acc, !1 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        INIT_FCALL                                               'decbin'
          3        INIT_FCALL                                               'ord'
          4        SEND_VAR                                                 !1
          5        DO_ICALL                                         $2      
          6        SEND_VAR                                                 $2
          7        DO_ICALL                                         $3      
          8        ASSIGN_OP                                     8  ~4      !0, $3
          9      > RETURN                                                   ~4
         10*     > RETURN                                                   null

End of Dynamic Function 0

End of function ascii2bin

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
134.05 ms | 1467 KiB | 29 Q