Skip to content

Commit 9b1e7cf

Browse files
Francesc Campoybroady
Francesc Campoy
authored andcommitted
math/bits: add examples for OnesCount functions
Change-Id: Ie673f9665825a40281c2584d478ba1260f725856 Reviewed-on: https://go-review.googlesource.com/53357 Run-TryBot: Chris Broadfoot <[email protected]> Reviewed-by: Chris Broadfoot <[email protected]>
1 parent b01db02 commit 9b1e7cf

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

src/math/bits/example_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,43 @@ func ExampleLeadingZeros64() {
3636
// 64
3737
// 63
3838
}
39+
40+
func ExampleOnesCount() {
41+
fmt.Printf("%b\n", 14)
42+
fmt.Println(bits.OnesCount(14))
43+
// Output:
44+
// 1110
45+
// 3
46+
}
47+
48+
func ExampleOnesCount8() {
49+
fmt.Printf("%b\n", 14)
50+
fmt.Println(bits.OnesCount8(14))
51+
// Output:
52+
// 1110
53+
// 3
54+
}
55+
56+
func ExampleOnesCount16() {
57+
fmt.Printf("%b\n", 14)
58+
fmt.Println(bits.OnesCount16(14))
59+
// Output:
60+
// 1110
61+
// 3
62+
}
63+
64+
func ExampleOnesCount32() {
65+
fmt.Printf("%b\n", 14)
66+
fmt.Println(bits.OnesCount32(14))
67+
// Output:
68+
// 1110
69+
// 3
70+
}
71+
72+
func ExampleOnesCount64() {
73+
fmt.Printf("%b\n", 14)
74+
fmt.Println(bits.OnesCount(14))
75+
// Output:
76+
// 1110
77+
// 3
78+
}

0 commit comments

Comments
 (0)