fork download
  1. package main
  2.  
  3. import (
  4. "fmt"
  5. "strconv"
  6. )
  7.  
  8. const MAX_BITS = 5
  9.  
  10. func main(){
  11. var input string
  12. fmt.Scanln(&input)
  13. x, err := strconv.Atoi(input)
  14. if err != nil {
  15. panic(err)
  16. }
  17.  
  18. bitCnt := 0
  19. for i := uint(0); i < MAX_BITS; i++ {
  20. if (x >> i) & 1 != 0 {
  21. bitCnt++
  22. }
  23. }
  24.  
  25. fmt.Printf("Bit count for %d: %d\n", x, bitCnt)
  26. }
Success #stdin #stdout 0s 789504KB
stdin
14
stdout
Bit count for 14: 3