From 89bcbf40b86ebad81d5cf34f6457f11a6f23b808 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Thu, 2 Nov 2017 11:19:23 +0100 Subject: 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 TryBot-Result: Gobot Gobot Reviewed-by: Robert Griesemer --- src/math/bits/example_test.go | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/math/bits/example_test.go') 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() { -- cgit v1.3-5-g9baa