/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class First
{
{
System.
out.
println(hitungNomorBit
(13,
0)); System.
out.
println(hitungNomorBit
(13,
1)); System.
out.
println(hitungNomorBit
(13,
2)); System.
out.
println(hitungNomorBit
(13,
3)); }
public static Integer hitungNomorBit
(int angka,
int nomorBit
) { if (nomorBit != 0 && nomorBit != 1) {
return null;
}
if (angka == 0) {
return nomorBit == 0 ? 1 : 0;
}
while (angka != 0) {
if ((angka & 1) == nomorBit) {
answer += 1;
}
angka = angka >>> 1;
}
return answer;
}
}
LyogcGFja2FnZSB3aGF0ZXZlcjsgLy8gZG9uJ3QgcGxhY2UgcGFja2FnZSBuYW1lISAqLwogCmltcG9ydCBqYXZhLnV0aWwuKjsKaW1wb3J0IGphdmEubGFuZy4qOwppbXBvcnQgamF2YS5pby4qOwogCi8qIE5hbWUgb2YgdGhlIGNsYXNzIGhhcyB0byBiZSAiTWFpbiIgb25seSBpZiB0aGUgY2xhc3MgaXMgcHVibGljLiAqLwpjbGFzcyBGaXJzdAp7CglwdWJsaWMgc3RhdGljIHZvaWQgbWFpbiAoU3RyaW5nW10gYXJncykgdGhyb3dzIGphdmEubGFuZy5FeGNlcHRpb24KCXsKCQlTeXN0ZW0ub3V0LnByaW50bG4oaGl0dW5nTm9tb3JCaXQoMTMsIDApKTsKICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oaGl0dW5nTm9tb3JCaXQoMTMsIDEpKTsKICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oaGl0dW5nTm9tb3JCaXQoMTMsIDIpKTsKICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oaGl0dW5nTm9tb3JCaXQoMTMsIDMpKTsKCX0KIAoJcHVibGljIHN0YXRpYyBJbnRlZ2VyIGhpdHVuZ05vbW9yQml0KGludCBhbmdrYSwgaW50IG5vbW9yQml0KSB7CgkJaWYgKG5vbW9yQml0ICE9IDAgJiYgb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