Commit 776e1709 authored by adarsh ravichandran's avatar adarsh ravichandran Committed by Brad Fitzpatrick

math/bits: add example for OnesCount function

Change-Id: Id87db9bed5e8715d554c1bf95c063d7d0a03c3e9
Reviewed-on: https://go-review.googlesource.com/c/go/+/178117
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent c77a9e0a
......@@ -59,6 +59,12 @@ func ExampleTrailingZeros64() {
// TrailingZeros64(0000000000000000000000000000000000000000000000000000000000001110) = 1
}
func ExampleOnesCount() {
fmt.Printf("OnesCount(%b) = %d\n", 14, bits.OnesCount(14))
// Output:
// OnesCount(1110) = 3
}
func ExampleOnesCount8() {
fmt.Printf("OnesCount8(%08b) = %d\n", 14, bits.OnesCount8(14))
// Output:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment