diff options
| author | adarsh ravichandran <adarshravichandran91@gmail.com> | 2019-05-20 16:27:13 +0530 |
|---|---|---|
| committer | Brad Fitzpatrick <bradfitz@golang.org> | 2019-05-20 18:16:09 +0000 |
| commit | 776e1709e59c2c50d93467e666d4bb8955b32ed3 (patch) | |
| tree | 8ab79f4e7b5cdec7db77d488d54a11648c8e66bd /src/math/bits/example_test.go | |
| parent | c77a9e0aa5a8a238d68aa82b3b7e052a314a0060 (diff) | |
| download | go-776e1709e59c2c50d93467e666d4bb8955b32ed3.tar.xz | |
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: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/math/bits/example_test.go')
| -rw-r--r-- | src/math/bits/example_test.go | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/math/bits/example_test.go b/src/math/bits/example_test.go index 18e026b9b4..b2ed2cba4b 100644 --- a/src/math/bits/example_test.go +++ b/src/math/bits/example_test.go @@ -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: |
