<?php
function active_cells(int $mask): array {
    $cells = [];
    $cell = 1;
    $remainingMask = $mask;
    while ($remainingMask > 0) {
        if (($remainingMask % 2) === 1) {
            $cells[] = $cell;
        }
        $remainingMask = (int) floor($remainingMask / 2);
        $cell++;
    }
    return $cells;
}

foreach (active_cells(0b10101) as $cell) {
    echo $cell, PHP_EOL;
}
