aboutsummaryrefslogtreecommitdiff
path: root/src/math/bits/example_test.go
diff options
context:
space:
mode:
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
+}