diff options
| author | Tobias Klauser <tklauser@distanz.ch> | 2017-11-02 11:19:23 +0100 |
|---|---|---|
| committer | Robert Griesemer <gri@golang.org> | 2017-11-03 20:12:07 +0000 |
| commit | 89bcbf40b86ebad81d5cf34f6457f11a6f23b808 (patch) | |
| tree | 3cc56b5df65a744c66009891634bdcb99f895604 /src/math/bits/example_test.go | |
| parent | 483e298daad38f39515ba20c0fcedc20b5475ae8 (diff) | |
| download | go-89bcbf40b86ebad81d5cf34f6457f11a6f23b808.tar.xz | |
math/bits: add examples for right rotation
Right rotation is achieved using negative k in RotateLeft*(x, k). Add
examples demonstrating that functionality.
Change-Id: I15dab159accd2937cb18d3fa8ca32da8501567d3
Reviewed-on: https://go-review.googlesource.com/75371
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
Diffstat (limited to 'src/math/bits/example_test.go')
| -rw-r--r-- | src/math/bits/example_test.go | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/math/bits/example_test.go b/src/math/bits/example_test.go index dd400da0fe..18e026b9b4 100644 --- a/src/math/bits/example_test.go +++ b/src/math/bits/example_test.go @@ -86,33 +86,41 @@ func ExampleOnesCount64() { func ExampleRotateLeft8() { fmt.Printf("%08b\n", 15) fmt.Printf("%08b\n", bits.RotateLeft8(15, 2)) + fmt.Printf("%08b\n", bits.RotateLeft8(15, -2)) // Output: // 00001111 // 00111100 + // 11000011 } func ExampleRotateLeft16() { fmt.Printf("%016b\n", 15) fmt.Printf("%016b\n", bits.RotateLeft16(15, 2)) + fmt.Printf("%016b\n", bits.RotateLeft16(15, -2)) // Output: // 0000000000001111 // 0000000000111100 + // 1100000000000011 } func ExampleRotateLeft32() { fmt.Printf("%032b\n", 15) fmt.Printf("%032b\n", bits.RotateLeft32(15, 2)) + fmt.Printf("%032b\n", bits.RotateLeft32(15, -2)) // Output: // 00000000000000000000000000001111 // 00000000000000000000000000111100 + // 11000000000000000000000000000011 } func ExampleRotateLeft64() { fmt.Printf("%064b\n", 15) fmt.Printf("%064b\n", bits.RotateLeft64(15, 2)) + fmt.Printf("%064b\n", bits.RotateLeft64(15, -2)) // Output: // 0000000000000000000000000000000000000000000000000000000000001111 // 0000000000000000000000000000000000000000000000000000000000111100 + // 1100000000000000000000000000000000000000000000000000000000000011 } func ExampleReverse8() { |
