3v4l.org

run code in 300+ PHP versions simultaneously
<?php $int = 5; $bits = []; function int_to_bools($int, $count) { $bools = []; for ($i = 0; $i < $count; $i++) { $bools[$i] = (bool)($int & (2 ** $i)); } return $bools; } function bools_to_int($bools) { $int = 0; foreach (array_values($bools) as $i => $bit) { $int |= ((int)$bit) << $i; } return $int; } $int = 5; $bools = int_to_bools($int, 10); var_dump($bools); $int = bools_to_int($bools); var_dump($int);

preferences:
42.75 ms | 1752 KiB | 5 Q