Source file
src/math/bits/example_test.go
1
2
3
4
5
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
17
18 }
19
20 func ExampleLeadingZeros16() {
21 fmt.Printf("LeadingZeros16(%016b) = %d\n", 1, bits.LeadingZeros16(1))
22
23
24 }
25
26 func ExampleLeadingZeros32() {
27 fmt.Printf("LeadingZeros32(%032b) = %d\n", 1, bits.LeadingZeros32(1))
28
29
30 }
31
32 func ExampleLeadingZeros64() {
33 fmt.Printf("LeadingZeros64(%064b) = %d\n", 1, bits.LeadingZeros64(1))
34
35
36 }
37
38 func ExampleTrailingZeros8() {
39 fmt.Printf("TrailingZeros8(%08b) = %d\n", 14, bits.TrailingZeros8(14))
40
41
42 }
43
44 func ExampleTrailingZeros16() {
45 fmt.Printf("TrailingZeros16(%016b) = %d\n", 14, bits.TrailingZeros16(14))
46
47
48 }
49
50 func ExampleTrailingZeros32() {
51 fmt.Printf("TrailingZeros32(%032b) = %d\n", 14, bits.TrailingZeros32(14))
52
53
54 }
55
56 func ExampleTrailingZeros64() {
57 fmt.Printf("TrailingZeros64(%064b) = %d\n", 14, bits.TrailingZeros64(14))
58
59
60 }
61
62 func ExampleOnesCount() {
63 fmt.Printf("OnesCount(%b) = %d\n", 14, bits.OnesCount(14))
64
65
66 }
67
68 func ExampleOnesCount8() {
69 fmt.Printf("OnesCount8(%08b) = %d\n", 14, bits.OnesCount8(14))
70
71
72 }
73
74 func ExampleOnesCount16() {
75 fmt.Printf("OnesCount16(%016b) = %d\n", 14, bits.OnesCount16(14))
76
77
78 }
79
80 func ExampleOnesCount32() {
81 fmt.Printf("OnesCount32(%032b) = %d\n", 14, bits.OnesCount32(14))
82
83
84 }
85
86 func ExampleOnesCount64() {
87 fmt.Printf("OnesCount64(%064b) = %d\n", 14, bits.OnesCount64(14))
88
89
90 }
91
92 func ExampleRotateLeft8() {
93 fmt.Printf("%08b\n", 15)
94 fmt.Printf("%08b\n", bits.RotateLeft8(15, 2))
95 fmt.Printf("%08b\n", bits.RotateLeft8(15, -2))
96
97
98
99
100 }
101
102 func ExampleRotateLeft16() {
103 fmt.Printf("%016b\n", 15)
104 fmt.Printf("%016b\n", bits.RotateLeft16(15, 2))
105 fmt.Printf("%016b\n", bits.RotateLeft16(15, -2))
106
107
108
109
110 }
111
112 func ExampleRotateLeft32() {
113 fmt.Printf("%032b\n", 15)
114 fmt.Printf("%032b\n", bits.RotateLeft32(15, 2))
115 fmt.Printf("%032b\n", bits.RotateLeft32(15, -2))
116
117
118
119
120 }
121
122 func ExampleRotateLeft64() {
123 fmt.Printf("%064b\n", 15)
124 fmt.Printf("%064b\n", bits.RotateLeft64(15, 2))
125 fmt.Printf("%064b\n", bits.RotateLeft64(15, -2))
126
127
128
129
130 }
131
132 func ExampleReverse8() {
133 fmt.Printf("%08b\n", 19)
134 fmt.Printf("%08b\n", bits.Reverse8(19))
135
136
137
138 }
139
140 func ExampleReverse16() {
141 fmt.Printf("%016b\n", 19)
142 fmt.Printf("%016b\n", bits.Reverse16(19))
143
144
145
146 }
147
148 func ExampleReverse32() {
149 fmt.Printf("%032b\n", 19)
150 fmt.Printf("%032b\n", bits.Reverse32(19))
151
152
153
154 }
155
156 func ExampleReverse64() {
157 fmt.Printf("%064b\n", 19)
158 fmt.Printf("%064b\n", bits.Reverse64(19))
159
160
161
162 }
163
164 func ExampleReverseBytes16() {
165 fmt.Printf("%016b\n", 15)
166 fmt.Printf("%016b\n", bits.ReverseBytes16(15))
167
168
169
170 }
171
172 func ExampleReverseBytes32() {
173 fmt.Printf("%032b\n", 15)
174 fmt.Printf("%032b\n", bits.ReverseBytes32(15))
175
176
177
178 }
179
180 func ExampleReverseBytes64() {
181 fmt.Printf("%064b\n", 15)
182 fmt.Printf("%064b\n", bits.ReverseBytes64(15))
183
184
185
186 }
187
188 func ExampleLen8() {
189 fmt.Printf("Len8(%08b) = %d\n", 8, bits.Len8(8))
190
191
192 }
193
194 func ExampleLen16() {
195 fmt.Printf("Len16(%016b) = %d\n", 8, bits.Len16(8))
196
197
198 }
199
200 func ExampleLen32() {
201 fmt.Printf("Len32(%032b) = %d\n", 8, bits.Len32(8))
202
203
204 }
205
206 func ExampleLen64() {
207 fmt.Printf("Len64(%064b) = %d\n", 8, bits.Len64(8))
208
209
210 }
211
View as plain text