]> Cypherpunks repositories - gostls13.git/commitdiff
math/bits: add example for OnesCount function
authoradarsh ravichandran <adarshravichandran91@gmail.com>
Mon, 20 May 2019 10:57:13 +0000 (16:27 +0530)
committerBrad Fitzpatrick <bradfitz@golang.org>
Mon, 20 May 2019 18:16:09 +0000 (18:16 +0000)
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: Brad Fitzpatrick <bradfitz@golang.org>
src/math/bits/example_test.go

index 18e026b9b466525a410706686a734127d06bbe7f..b2ed2cba4bfb72287dd1189382684baf41995e51 100644 (file)
@@ -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: