3v4l.org

run code in 300+ PHP versions simultaneously
<?php function pack_encode($val) { $str = ''; while ($val > 0) { $str .= chr($val & 0xFF); $val = $val >> 8; } // "/" json-encodes poorly and "=" is padding return str_replace( array('/', '='), array('_', ''), base64_encode($str) ); } function pack_decode($bin) { $str = base64_decode(str_replace('_', '/', $bin)); $val = 0; for ($i=0; $i<strlen($str); $i++) { $val |= (ord($str[$i]) << ($i * 8)); } return $val; } for ($i=0; $i<32; $i++) { $val = 1<<$i; $enc = pack_encode($val); $dec = pack_decode($enc); echo "$val => $enc => $dec\n"; } for ($i=1; $i< 1<<32; $i = $i<<1) { $enc = pack_encode($val); $dec = pack_decode($val); echo "$enc $dec $val\n"; }
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
1 => AQ => 1 2 => Ag => 2 4 => BA => 4 8 => CA => 8 16 => EA => 16 32 => IA => 32 64 => QA => 64 128 => gA => 128 256 => AAE => 256 512 => AAI => 512 1024 => AAQ => 1024 2048 => AAg => 2048 4096 => ABA => 4096 8192 => ACA => 8192 16384 => AEA => 16384 32768 => AIA => 32768 65536 => AAAB => 65536 131072 => AAAC => 131072 262144 => AAAE => 262144 524288 => AAAI => 524288 1048576 => AAAQ => 1048576 2097152 => AAAg => 2097152 4194304 => AABA => 4194304 8388608 => AACA => 8388608 16777216 => AAAAAQ => 16777216 33554432 => AAAAAg => 33554432 67108864 => AAAABA => 67108864 134217728 => AAAACA => 134217728 268435456 => AAAAEA => 268435456 536870912 => AAAAIA => 536870912 1073741824 => AAAAQA => 1073741824 2147483648 => AAAAgA => 2147483648 Fatal error: Uncaught Error: Undefined constant " 1" in /in/LsDF0:33 Stack trace: #0 {main} thrown in /in/LsDF0 on line 33
Process exited with code 255.
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 1 => AQ => 1 2 => Ag => 2 4 => BA => 4 8 => CA => 8 16 => EA => 16 32 => IA => 32 64 => QA => 64 128 => gA => 128 256 => AAE => 256 512 => AAI => 512 1024 => AAQ => 1024 2048 => AAg => 2048 4096 => ABA => 4096 8192 => ACA => 8192 16384 => AEA => 16384 32768 => AIA => 32768 65536 => AAAB => 65536 131072 => AAAC => 131072 262144 => AAAE => 262144 524288 => AAAI => 524288 1048576 => AAAQ => 1048576 2097152 => AAAg => 2097152 4194304 => AABA => 4194304 8388608 => AACA => 8388608 16777216 => AAAAAQ => 16777216 33554432 => AAAAAg => 33554432 67108864 => AAAABA => 67108864 134217728 => AAAACA => 134217728 268435456 => AAAAEA => 268435456 536870912 => AAAAIA => 536870912 1073741824 => AAAAQA => 1073741824 2147483648 => AAAAgA => 2147483648 Fatal error: Uncaught Error: Undefined constant " 1" in /in/LsDF0:33 Stack trace: #0 {main} thrown in /in/LsDF0 on line 33
Process exited with code 255.
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
1 => AQ => 1 2 => Ag => 2 4 => BA => 4 8 => CA => 8 16 => EA => 16 32 => IA => 32 64 => QA => 64 128 => gA => 128 256 => AAE => 256 512 => AAI => 512 1024 => AAQ => 1024 2048 => AAg => 2048 4096 => ABA => 4096 8192 => ACA => 8192 16384 => AEA => 16384 32768 => AIA => 32768 65536 => AAAB => 65536 131072 => AAAC => 131072 262144 => AAAE => 262144 524288 => AAAI => 524288 1048576 => AAAQ => 1048576 2097152 => AAAg => 2097152 4194304 => AABA => 4194304 8388608 => AACA => 8388608 16777216 => AAAAAQ => 16777216 33554432 => AAAAAg => 33554432 67108864 => AAAABA => 67108864 134217728 => AAAACA => 134217728 268435456 => AAAAEA => 268435456 536870912 => AAAAIA => 536870912 1073741824 => AAAAQA => 1073741824 2147483648 => AAAAgA => 2147483648 Warning: Use of undefined constant  1 - assumed ' 1' (this will throw an Error in a future version of PHP) in /in/LsDF0 on line 33 Warning: A non-numeric value encountered in /in/LsDF0 on line 33
Output for 7.1.0 - 7.1.25
1 => AQ => 1 2 => Ag => 2 4 => BA => 4 8 => CA => 8 16 => EA => 16 32 => IA => 32 64 => QA => 64 128 => gA => 128 256 => AAE => 256 512 => AAI => 512 1024 => AAQ => 1024 2048 => AAg => 2048 4096 => ABA => 4096 8192 => ACA => 8192 16384 => AEA => 16384 32768 => AIA => 32768 65536 => AAAB => 65536 131072 => AAAC => 131072 262144 => AAAE => 262144 524288 => AAAI => 524288 1048576 => AAAQ => 1048576 2097152 => AAAg => 2097152 4194304 => AABA => 4194304 8388608 => AACA => 8388608 16777216 => AAAAAQ => 16777216 33554432 => AAAAAg => 33554432 67108864 => AAAABA => 67108864 134217728 => AAAACA => 134217728 268435456 => AAAAEA => 268435456 536870912 => AAAAIA => 536870912 1073741824 => AAAAQA => 1073741824 2147483648 => AAAAgA => 2147483648 Notice: Use of undefined constant  1 - assumed ' 1' in /in/LsDF0 on line 33 Warning: A non-numeric value encountered in /in/LsDF0 on line 33
Output for 4.3.0 - 4.3.11, 4.4.0 - 4.4.9, 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20
1 => AQ => 1 2 => Ag => 2 4 => BA => 4 8 => CA => 8 16 => EA => 16 32 => IA => 32 64 => QA => 64 128 => gA => 128 256 => AAE => 256 512 => AAI => 512 1024 => AAQ => 1024 2048 => AAg => 2048 4096 => ABA => 4096 8192 => ACA => 8192 16384 => AEA => 16384 32768 => AIA => 32768 65536 => AAAB => 65536 131072 => AAAC => 131072 262144 => AAAE => 262144 524288 => AAAI => 524288 1048576 => AAAQ => 1048576 2097152 => AAAg => 2097152 4194304 => AABA => 4194304 8388608 => AACA => 8388608 16777216 => AAAAAQ => 16777216 33554432 => AAAAAg => 33554432 67108864 => AAAABA => 67108864 134217728 => AAAACA => 134217728 268435456 => AAAAEA => 268435456 536870912 => AAAAIA => 536870912 1073741824 => AAAAQA => 1073741824 2147483648 => AAAAgA => 2147483648 Notice: Use of undefined constant  1 - assumed ' 1' in /in/LsDF0 on line 33

preferences:
245.72 ms | 405 KiB | 368 Q