From 776e1709e59c2c50d93467e666d4bb8955b32ed3 Mon Sep 17 00:00:00 2001 From: adarsh ravichandran Date: Mon, 20 May 2019 16:27:13 +0530 Subject: [PATCH] math/bits: add example for OnesCount function Change-Id: Id87db9bed5e8715d554c1bf95c063d7d0a03c3e9 Reviewed-on: https://go-review.googlesource.com/c/go/+/178117 Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/math/bits/example_test.go | 6 ++++++ 1 file changed, 6 insertions(+) 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: -- 2.50.0