package main
import "fmt"
func hitungNomorBit(angka int, nomorBit int) *int {
if nomorBit != 0 && nomorBit != 1 {
return nil }
if angka == 0 {
count := 0
if nomorBit == 0 {
count = 1
}
return &count
}
count := 0
temp := angka
for temp > 0 {
sisa := temp % 2
if sisa == nomorBit {
count++
}
temp = temp / 2
}
return &count
}
func main(){
fmt.Println(*hitungNomorBit(13,0))
fmt.Println(*hitungNomorBit(13,1))
fmt.Println(hitungNomorBit(13,2))
}
cGFja2FnZSBtYWluCmltcG9ydCAiZm10IgoKZnVuYyBoaXR1bmdOb21vckJpdChhbmdrYSBpbnQsIG5vbW9yQml0IGludCkgKmludCB7CmlmIG5vbW9yQml0ICE9IDAgJiYgbm9tb3JCaXQgIT0gMSB7CnJldHVybiBuaWwgfQoKaWYgYW5na2EgPT0gMCB7CmNvdW50IDo9IDAKaWYgbm9tb3JCaXQgPT0gMCB7CmNvdW50ID0gMQp9CnJldHVybiAmY291bnQKfQoKY291bnQgOj0gMAp0ZW1wIDo9IGFuZ2thCgpmb3IgdGVtcCA+IDAgewpzaXNhIDo9IHRlbXAgJSAyCmlmIHNpc2EgPT0gbm9tb3JCaXQgewpjb3VudCsrCn0KdGVtcCA9IHRlbXAgLyAyCn0KcmV0dXJuICZjb3VudAoKfQoKZnVuYyBtYWluKCl7CglmbXQuUHJpbnRsbigqaGl0dW5nTm9tb3JCaXQoMTMsMCkpCglmbXQuUHJpbnRsbigqaGl0dW5nTm9tb3JCaXQoMTMsMSkpCglmbXQuUHJpbnRsbihoaXR1bmdOb21vckJpdCgxMywyKSkKfQ==