aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrancesc Campoy <francesc@campoy.cat>2017-08-04 15:41:57 -0700
committerChris Broadfoot <cbro@golang.org>2017-08-04 23:24:07 +0000
commit9b1e7cf2ac90d2c4637cae480957e0f0152c3622 (patch)
tree99b1420a6ad1e68b0df42bdca54f146269079fee
parentb01db023b13f9debdcc101ab6836b89be8bfa7f3 (diff)
downloadgo-9b1e7cf2ac90d2c4637cae480957e0f0152c3622.tar.gz
go-9b1e7cf2ac90d2c4637cae480957e0f0152c3622.zip
math/bits: add examples for OnesCount functions
Change-Id: Ie673f9665825a40281c2584d478ba1260f725856 Reviewed-on: https://go-review.googlesource.com/53357 Run-TryBot: Chris Broadfoot <cbro@golang.org> Reviewed-by: Chris Broadfoot <cbro@golang.org>
-rw-r--r--src/math/bits/example_test.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/math/bits/example_test.go b/src/math/bits/example_test.go
index 5d30f4b259..9836245cfb 100644
--- a/src/math/bits/example_test.go
+++ b/src/math/bits/example_test.go
@@ -36,3 +36,43 @@ func ExampleLeadingZeros64() {
// 64
// 63
}
+
+func ExampleOnesCount() {
+ fmt.Printf("%b\n", 14)
+ fmt.Println(bits.OnesCount(14))
+ // Output:
+ // 1110
+ // 3
+}
+
+func ExampleOnesCount8() {
+ fmt.Printf("%b\n", 14)
+ fmt.Println(bits.OnesCount8(14))
+ // Output:
+ // 1110
+ // 3
+}
+
+func ExampleOnesCount16() {
+ fmt.Printf("%b\n", 14)
+ fmt.Println(bits.OnesCount16(14))
+ // Output:
+ // 1110
+ // 3
+}
+
+func ExampleOnesCount32() {
+ fmt.Printf("%b\n", 14)
+ fmt.Println(bits.OnesCount32(14))
+ // Output:
+ // 1110
+ // 3
+}
+
+func ExampleOnesCount64() {
+ fmt.Printf("%b\n", 14)
+ fmt.Println(bits.OnesCount(14))
+ // Output:
+ // 1110
+ // 3
+}