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() {
name string
in int
out [4]interface{}
+ out2 [4]interface{}
}{
{
name: "LeadingZeros",
name: "RotateLeft",
in: 15,
out: [4]interface{}{bits.RotateLeft8(15, 2), bits.RotateLeft16(15, 2), bits.RotateLeft32(15, 2), bits.RotateLeft64(15, 2)},
+ out2: [4]interface{}{bits.RotateLeft8(15, -2), bits.RotateLeft16(15, -2), bits.RotateLeft32(15, -2), bits.RotateLeft64(15, -2)},
},
{
name: "Reverse",
fmt.Fprintf(w, "\tfmt.Printf(\"%%0%db\\n\", %d)\n", size, e.in)
if e.name == "RotateLeft" {
fmt.Fprintf(w, "\tfmt.Printf(\"%%0%db\\n\", bits.%s(%d, 2))\n", size, f, e.in)
+ fmt.Fprintf(w, "\tfmt.Printf(\"%%0%db\\n\", bits.%s(%d, -2))\n", size, f, e.in)
} else {
fmt.Fprintf(w, "\tfmt.Printf(\"%%0%db\\n\", bits.%s(%d))\n", size, f, e.in)
}
fmt.Fprintf(w, "\t// Output:\n")
fmt.Fprintf(w, "\t// %0*b\n", size, e.in)
fmt.Fprintf(w, "\t// %0*b\n", size, e.out[i])
+ if e.name == "RotateLeft" && e.out2[i] != nil {
+ fmt.Fprintf(w, "\t// %0*b\n", size, e.out2[i])
+ }
default:
fmt.Fprintf(w, "\tfmt.Printf(\"%s(%%0%db) = %%d\\n\", %d, bits.%s(%d))\n", f, size, e.in, f, e.in)
fmt.Fprintf(w, "\t// Output:\n")