]> Cypherpunks repositories - gostls13.git/commitdiff
math/bits: add examples for OnesCount functions
authorFrancesc Campoy <francesc@campoy.cat>
Fri, 4 Aug 2017 22:41:57 +0000 (15:41 -0700)
committerChris Broadfoot <cbro@golang.org>
Fri, 4 Aug 2017 23:24:07 +0000 (23:24 +0000)
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>
src/math/bits/example_test.go

index 5d30f4b259970343cd1f977e62334f3ecce033fb..9836245cfb925f01917e53c4c4ee75f66206b7ce 100644 (file)
@@ -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
+}