github.com/mattn/go@v0.0.0-20171011075504-07f7db3ea99f/src/math/bits/example_test.go (about) 1 // Copyright 2017 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // Code generated by go run make_examples.go. DO NOT EDIT. 6 7 package bits_test 8 9 import ( 10 "fmt" 11 "math/bits" 12 ) 13 14 func ExampleLeadingZeros8() { 15 fmt.Printf("LeadingZeros8(%08b) = %d\n", 1, bits.LeadingZeros8(1)) 16 // Output: 17 // LeadingZeros8(00000001) = 7 18 } 19 20 func ExampleLeadingZeros16() { 21 fmt.Printf("LeadingZeros16(%016b) = %d\n", 1, bits.LeadingZeros16(1)) 22 // Output: 23 // LeadingZeros16(0000000000000001) = 15 24 } 25 26 func ExampleLeadingZeros32() { 27 fmt.Printf("LeadingZeros32(%032b) = %d\n", 1, bits.LeadingZeros32(1)) 28 // Output: 29 // LeadingZeros32(00000000000000000000000000000001) = 31 30 } 31 32 func ExampleLeadingZeros64() { 33 fmt.Printf("LeadingZeros64(%064b) = %d\n", 1, bits.LeadingZeros64(1)) 34 // Output: 35 // LeadingZeros64(0000000000000000000000000000000000000000000000000000000000000001) = 63 36 } 37 38 func ExampleTrailingZeros8() { 39 fmt.Printf("TrailingZeros8(%08b) = %d\n", 14, bits.TrailingZeros8(14)) 40 // Output: 41 // TrailingZeros8(00001110) = 1 42 } 43 44 func ExampleTrailingZeros16() { 45 fmt.Printf("TrailingZeros16(%016b) = %d\n", 14, bits.TrailingZeros16(14)) 46 // Output: 47 // TrailingZeros16(0000000000001110) = 1 48 } 49 50 func ExampleTrailingZeros32() { 51 fmt.Printf("TrailingZeros32(%032b) = %d\n", 14, bits.TrailingZeros32(14)) 52 // Output: 53 // TrailingZeros32(00000000000000000000000000001110) = 1 54 } 55 56 func ExampleTrailingZeros64() { 57 fmt.Printf("TrailingZeros64(%064b) = %d\n", 14, bits.TrailingZeros64(14)) 58 // Output: 59 // TrailingZeros64(0000000000000000000000000000000000000000000000000000000000001110) = 1 60 } 61 62 func ExampleOnesCount8() { 63 fmt.Printf("OnesCount8(%08b) = %d\n", 14, bits.OnesCount8(14)) 64 // Output: 65 // OnesCount8(00001110) = 3 66 } 67 68 func ExampleOnesCount16() { 69 fmt.Printf("OnesCount16(%016b) = %d\n", 14, bits.OnesCount16(14)) 70 // Output: 71 // OnesCount16(0000000000001110) = 3 72 } 73 74 func ExampleOnesCount32() { 75 fmt.Printf("OnesCount32(%032b) = %d\n", 14, bits.OnesCount32(14)) 76 // Output: 77 // OnesCount32(00000000000000000000000000001110) = 3 78 } 79 80 func ExampleOnesCount64() { 81 fmt.Printf("OnesCount64(%064b) = %d\n", 14, bits.OnesCount64(14)) 82 // Output: 83 // OnesCount64(0000000000000000000000000000000000000000000000000000000000001110) = 3 84 } 85 86 func ExampleRotateLeft8() { 87 fmt.Printf("%08b\n", 15) 88 fmt.Printf("%08b\n", bits.RotateLeft8(15, 2)) 89 // Output: 90 // 00001111 91 // 00111100 92 } 93 94 func ExampleRotateLeft16() { 95 fmt.Printf("%016b\n", 15) 96 fmt.Printf("%016b\n", bits.RotateLeft16(15, 2)) 97 // Output: 98 // 0000000000001111 99 // 0000000000111100 100 } 101 102 func ExampleRotateLeft32() { 103 fmt.Printf("%032b\n", 15) 104 fmt.Printf("%032b\n", bits.RotateLeft32(15, 2)) 105 // Output: 106 // 00000000000000000000000000001111 107 // 00000000000000000000000000111100 108 } 109 110 func ExampleRotateLeft64() { 111 fmt.Printf("%064b\n", 15) 112 fmt.Printf("%064b\n", bits.RotateLeft64(15, 2)) 113 // Output: 114 // 0000000000000000000000000000000000000000000000000000000000001111 115 // 0000000000000000000000000000000000000000000000000000000000111100 116 } 117 118 func ExampleReverse8() { 119 fmt.Printf("%08b\n", 19) 120 fmt.Printf("%08b\n", bits.Reverse8(19)) 121 // Output: 122 // 00010011 123 // 11001000 124 } 125 126 func ExampleReverse16() { 127 fmt.Printf("%016b\n", 19) 128 fmt.Printf("%016b\n", bits.Reverse16(19)) 129 // Output: 130 // 0000000000010011 131 // 1100100000000000 132 } 133 134 func ExampleReverse32() { 135 fmt.Printf("%032b\n", 19) 136 fmt.Printf("%032b\n", bits.Reverse32(19)) 137 // Output: 138 // 00000000000000000000000000010011 139 // 11001000000000000000000000000000 140 } 141 142 func ExampleReverse64() { 143 fmt.Printf("%064b\n", 19) 144 fmt.Printf("%064b\n", bits.Reverse64(19)) 145 // Output: 146 // 0000000000000000000000000000000000000000000000000000000000010011 147 // 1100100000000000000000000000000000000000000000000000000000000000 148 } 149 150 func ExampleReverseBytes16() { 151 fmt.Printf("%016b\n", 15) 152 fmt.Printf("%016b\n", bits.ReverseBytes16(15)) 153 // Output: 154 // 0000000000001111 155 // 0000111100000000 156 } 157 158 func ExampleReverseBytes32() { 159 fmt.Printf("%032b\n", 15) 160 fmt.Printf("%032b\n", bits.ReverseBytes32(15)) 161 // Output: 162 // 00000000000000000000000000001111 163 // 00001111000000000000000000000000 164 } 165 166 func ExampleReverseBytes64() { 167 fmt.Printf("%064b\n", 15) 168 fmt.Printf("%064b\n", bits.ReverseBytes64(15)) 169 // Output: 170 // 0000000000000000000000000000000000000000000000000000000000001111 171 // 0000111100000000000000000000000000000000000000000000000000000000 172 } 173 174 func ExampleLen8() { 175 fmt.Printf("Len8(%08b) = %d\n", 8, bits.Len8(8)) 176 // Output: 177 // Len8(00001000) = 4 178 } 179 180 func ExampleLen16() { 181 fmt.Printf("Len16(%016b) = %d\n", 8, bits.Len16(8)) 182 // Output: 183 // Len16(0000000000001000) = 4 184 } 185 186 func ExampleLen32() { 187 fmt.Printf("Len32(%032b) = %d\n", 8, bits.Len32(8)) 188 // Output: 189 // Len32(00000000000000000000000000001000) = 4 190 } 191 192 func ExampleLen64() { 193 fmt.Printf("Len64(%064b) = %d\n", 8, bits.Len64(8)) 194 // Output: 195 // Len64(0000000000000000000000000000000000000000000000000000000000001000) = 4 196 }