function placeBit(&$array, $NR, $NC, $r, $c, $p, $b) {
        if ($r < 0) {
            $r += $NR;
            $c += 4 - (($NR + 4) % 8);
        }
        if ($c < 0) {
            $c += $NC;
            $r += 4 - (($NC + 4) % 8);
        }

        $array[$r * $NC + $c] = ($p << 3) + $b;
    }