Standard library / math/bits

bits.OnesCount32()

Counts set bits (population count) in the unsigned word. Expected stdout: '3\n'.

Formal Syntax & Structure

go syntaxgo
func OnesCount32(x uint32) int

Parameters & Attributes

NameTypeDescription
xuint32First input operand (or sole input if unary).

Return Value

int

Counts set bits (population count) in the unsigned word.

Working Example

Example Snippetgo
package main
import (  "fmt"  "math/bits")
func main() {  fmt.Println(bits.OnesCount32(11))}
Go Reference