<?php

function hitungNomorBit($angka, $nomorBit) {
    if ($nomorBit !== 0 && $nomorBit !== 1) {
        return null;
    }

    $biner = [];
    while ($angka > 0) {
        $sisa = $angka % 2;
        array_unshift($biner, $sisa);
        $angka = intdiv($angka, 2);
    }

    $jumlah = 0;
    foreach ($biner as $bit) {
        if ($bit === $nomorBit) {
            $jumlah++;
        }
    }

    return $jumlah > 0 ? $jumlah : null;
}

echo "hitungNomorBit(13, 0) = " . var_export(hitungNomorBit(13, 0), true) . PHP_EOL;
echo "hitungNomorBit(13, 1) = " . var_export(hitungNomorBit(13, 1), true) . PHP_EOL;
echo "hitungNomorBit(13, 2) = " . var_export(hitungNomorBit(13, 2), true) . PHP_EOL;

?>
