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; }
Output for git.master, git.master_jit, rfc.property-hooks

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
60.91 ms | 401 KiB | 8 Q