aboutsummaryrefslogtreecommitdiff
path: root/src/math/bits/example_test.go
diff options
context:
space:
mode:
authorgriesemer <gri@golang.org>2017-10-04 15:20:52 -0700
committerRobert Griesemer <gri@golang.org>2017-10-06 16:58:03 +0000
commit2ddd07138d08d12e5662b9480c1fb23d3feb6a5d (patch)
tree57088796039b1be112c2a36aef8981e845189c7b /src/math/bits/example_test.go
parentb77d9fe0ead35a30cbe449ae805bc4a8770b4a68 (diff)
downloadgo-2ddd07138d08d12e5662b9480c1fb23d3feb6a5d.tar.xz
math/bits: complete examples
Change-Id: Icbe6885ffd3aa4e77441ab03a2b9a04a9276d5eb Reviewed-on: https://go-review.googlesource.com/68311 Reviewed-by: Martin Möhrmann <moehrmann@google.com>
Diffstat (limited to 'src/math/bits/example_test.go')
-rw-r--r--src/math/bits/example_test.go80
1 files changed, 68 insertions, 12 deletions
diff --git a/src/math/bits/example_test.go b/src/math/bits/example_test.go
index f4ed259043..dd400da0fe 100644
--- a/src/math/bits/example_test.go
+++ b/src/math/bits/example_test.go
@@ -83,28 +83,36 @@ func ExampleOnesCount64() {
// OnesCount64(0000000000000000000000000000000000000000000000000000000000001110) = 3
}
-func ExampleLen8() {
- fmt.Printf("Len8(%08b) = %d\n", 8, bits.Len8(8))
+func ExampleRotateLeft8() {
+ fmt.Printf("%08b\n", 15)
+ fmt.Printf("%08b\n", bits.RotateLeft8(15, 2))
// Output:
- // Len8(00001000) = 4
+ // 00001111
+ // 00111100
}
-func ExampleLen16() {
- fmt.Printf("Len16(%016b) = %d\n", 8, bits.Len16(8))
+func ExampleRotateLeft16() {
+ fmt.Printf("%016b\n", 15)
+ fmt.Printf("%016b\n", bits.RotateLeft16(15, 2))
// Output:
- // Len16(0000000000001000) = 4
+ // 0000000000001111
+ // 0000000000111100
}
-func ExampleLen32() {
- fmt.Printf("Len32(%032b) = %d\n", 8, bits.Len32(8))
+func ExampleRotateLeft32() {
+ fmt.Printf("%032b\n", 15)
+ fmt.Printf("%032b\n", bits.RotateLeft32(15, 2))
// Output:
- // Len32(00000000000000000000000000001000) = 4
+ // 00000000000000000000000000001111
+ // 00000000000000000000000000111100
}
-func ExampleLen64() {
- fmt.Printf("Len64(%064b) = %d\n", 8, bits.Len64(8))
+func ExampleRotateLeft64() {
+ fmt.Printf("%064b\n", 15)
+ fmt.Printf("%064b\n", bits.RotateLeft64(15, 2))
// Output:
- // Len64(0000000000000000000000000000000000000000000000000000000000001000) = 4
+ // 0000000000000000000000000000000000000000000000000000000000001111
+ // 0000000000000000000000000000000000000000000000000000000000111100
}
func ExampleReverse8() {
@@ -138,3 +146,51 @@ func ExampleReverse64() {
// 0000000000000000000000000000000000000000000000000000000000010011
// 1100100000000000000000000000000000000000000000000000000000000000
}
+
+func ExampleReverseBytes16() {
+ fmt.Printf("%016b\n", 15)
+ fmt.Printf("%016b\n", bits.ReverseBytes16(15))
+ // Output:
+ // 0000000000001111
+ // 0000111100000000
+}
+
+func ExampleReverseBytes32() {
+ fmt.Printf("%032b\n", 15)
+ fmt.Printf("%032b\n", bits.ReverseBytes32(15))
+ // Output:
+ // 00000000000000000000000000001111
+ // 00001111000000000000000000000000
+}
+
+func ExampleReverseBytes64() {
+ fmt.Printf("%064b\n", 15)
+ fmt.Printf("%064b\n", bits.ReverseBytes64(15))
+ // Output:
+ // 0000000000000000000000000000000000000000000000000000000000001111
+ // 0000111100000000000000000000000000000000000000000000000000000000
+}
+
+func ExampleLen8() {
+ fmt.Printf("Len8(%08b) = %d\n", 8, bits.Len8(8))
+ // Output:
+ // Len8(00001000) = 4
+}
+
+func ExampleLen16() {
+ fmt.Printf("Len16(%016b) = %d\n", 8, bits.Len16(8))
+ // Output:
+ // Len16(0000000000001000) = 4
+}
+
+func ExampleLen32() {
+ fmt.Printf("Len32(%032b) = %d\n", 8, bits.Len32(8))
+ // Output:
+ // Len32(00000000000000000000000000001000) = 4
+}
+
+func ExampleLen64() {
+ fmt.Printf("Len64(%064b) = %d\n", 8, bits.Len64(8))
+ // Output:
+ // Len64(0000000000000000000000000000000000000000000000000000000000001000) = 4
+}