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);

This is an error 500

Value for `_results` contains invalid data `array`


preferences:
217.26 ms | 2375 KiB | 14 Q