1
0
mirror of https://github.com/golang/go synced 2024-09-28 20:14:28 -06:00

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>
This commit is contained in:
Francesc Campoy 2017-08-04 15:41:57 -07:00 committed by Chris Broadfoot
parent b01db023b1
commit 9b1e7cf2ac

View 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
}