#include <stdio.h>

int hitungNomorBit(int angka, int nomorBit) {
    int positions[128];
      
    int n = angka;
    int pos = 0;
    int count = 0; 

    // check the lowest bit each step; divide by 2 until 0
    while (n > 0) {
        if (n % 2 == 1) {
            positions[count] = pos;  // remember where a 1-bit is
            count++;
        }
        n = n / 2;
        pos++;
    }
	
	// return the spot that is asked for, check if it's valid
    if (nomorBit >= 0 && nomorBit < count - 1) {
        return positions[nomorBit] + 1; // start at 1
    }
    return -1; // null
}

int main() {
	// the three examples from the question
    int tests[3][2] = {{13, 0}, {13, 1}, {13, 2}}; 
    for (int i = 0; i < 3; i++) {
        int r = hitungNomorBit(tests[i][0], tests[i][1]);
        if (r == -1) {
            printf("hitungNomorBit(%d, %d) -> mengeluarkan hasil null\n", tests[i][0], tests[i][1]);
        } else {
            printf("hitungNomorBit(%d, %d) -> mengeluarkan hasil bilangan desimal %d\n", tests[i][0], tests[i][1], r);
        }
    }
    return 0;
}