Debian Codegraph @

src/math/bits/example_test.go

raw
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 ExampleOnesCount() {
63 fmt.Printf("OnesCount(%b) = %d\n", 14, bits.OnesCount(14))
64 // Output:
65 // OnesCount(1110) = 3
66 }
67
68 func ExampleOnesCount8() {
69 fmt.Printf("OnesCount8(%08b) = %d\n", 14, bits.OnesCount8(14))
70 // Output:
71 // OnesCount8(00001110) = 3
72 }
73
74 func ExampleOnesCount16() {
75 fmt.Printf("OnesCount16(%016b) = %d\n", 14, bits.OnesCount16(14))
76 // Output:
77 // OnesCount16(0000000000001110) = 3
78 }
79
80 func ExampleOnesCount32() {
81 fmt.Printf("OnesCount32(%032b) = %d\n", 14, bits.OnesCount32(14))
82 // Output:
83 // OnesCount32(00000000000000000000000000001110) = 3
84 }
85
86 func ExampleOnesCount64() {
87 fmt.Printf("OnesCount64(%064b) = %d\n", 14, bits.OnesCount64(14))
88 // Output:
89 // OnesCount64(0000000000000000000000000000000000000000000000000000000000001110) = 3
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 // Output:
97 // 00001111
98 // 00111100
99 // 11000011
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 // Output:
107 // 0000000000001111
108 // 0000000000111100
109 // 1100000000000011
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 // Output:
117 // 00000000000000000000000000001111
118 // 00000000000000000000000000111100
119 // 11000000000000000000000000000011
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 // Output:
127 // 0000000000000000000000000000000000000000000000000000000000001111
128 // 0000000000000000000000000000000000000000000000000000000000111100
129 // 1100000000000000000000000000000000000000000000000000000000000011
130 }
131
132 func ExampleReverse8() {
133 fmt.Printf("%08b\n", 19)
134 fmt.Printf("%08b\n", bits.Reverse8(19))
135 // Output:
136 // 00010011
137 // 11001000
138 }
139
140 func ExampleReverse16() {
141 fmt.Printf("%016b\n", 19)
142 fmt.Printf("%016b\n", bits.Reverse16(19))
143 // Output:
144 // 0000000000010011
145 // 1100100000000000
146 }
147
148 func ExampleReverse32() {
149 fmt.Printf("%032b\n", 19)
150 fmt.Printf("%032b\n", bits.Reverse32(19))
151 // Output:
152 // 00000000000000000000000000010011
153 // 11001000000000000000000000000000
154 }
155
156 func ExampleReverse64() {
157 fmt.Printf("%064b\n", 19)
158 fmt.Printf("%064b\n", bits.Reverse64(19))
159 // Output:
160 // 0000000000000000000000000000000000000000000000000000000000010011
161 // 1100100000000000000000000000000000000000000000000000000000000000
162 }
163
164 func ExampleReverseBytes16() {
165 fmt.Printf("%016b\n", 15)
166 fmt.Printf("%016b\n", bits.ReverseBytes16(15))
167 // Output:
168 // 0000000000001111
169 // 0000111100000000
170 }
171
172 func ExampleReverseBytes32() {
173 fmt.Printf("%032b\n", 15)
174 fmt.Printf("%032b\n", bits.ReverseBytes32(15))
175 // Output:
176 // 00000000000000000000000000001111
177 // 00001111000000000000000000000000
178 }
179
180 func ExampleReverseBytes64() {
181 fmt.Printf("%064b\n", 15)
182 fmt.Printf("%064b\n", bits.ReverseBytes64(15))
183 // Output:
184 // 0000000000000000000000000000000000000000000000000000000000001111
185 // 0000111100000000000000000000000000000000000000000000000000000000
186 }
187
188 func ExampleLen8() {
189 fmt.Printf("Len8(%08b) = %d\n", 8, bits.Len8(8))
190 // Output:
191 // Len8(00001000) = 4
192 }
193
194 func ExampleLen16() {
195 fmt.Printf("Len16(%016b) = %d\n", 8, bits.Len16(8))
196 // Output:
197 // Len16(0000000000001000) = 4
198 }
199
200 func ExampleLen32() {
201 fmt.Printf("Len32(%032b) = %d\n", 8, bits.Len32(8))
202 // Output:
203 // Len32(00000000000000000000000000001000) = 4
204 }
205
206 func ExampleLen64() {
207 fmt.Printf("Len64(%064b) = %d\n", 8, bits.Len64(8))
208 // Output:
209 // Len64(0000000000000000000000000000000000000000000000000000000000001000) = 4
210 }