summaryrefslogtreecommitdiffstats
path: root/src/math/bits/example_test.go
blob: b2ed2cba4bfb72287dd1189382684baf41995e51 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
// Copyright 2017 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// Code generated by go run make_examples.go. DO NOT EDIT.

package bits_test

import (
	"fmt"
	"math/bits"
)

func ExampleLeadingZeros8() {
	fmt.Printf("LeadingZeros8(%08b) = %d\n", 1, bits.LeadingZeros8(1))
	// Output:
	// LeadingZeros8(00000001) = 7
}

func ExampleLeadingZeros16() {
	fmt.Printf("LeadingZeros16(%016b) = %d\n", 1, bits.LeadingZeros16(1))
	// Output:
	// LeadingZeros16(0000000000000001) = 15
}

func ExampleLeadingZeros32() {
	fmt.Printf("LeadingZeros32(%032b) = %d\n", 1, bits.LeadingZeros32(1))
	// Output:
	// LeadingZeros32(00000000000000000000000000000001) = 31
}

func ExampleLeadingZeros64() {
	fmt.Printf("LeadingZeros64(%064b) = %d\n", 1, bits.LeadingZeros64(1))
	// Output:
	// LeadingZeros64(0000000000000000000000000000000000000000000000000000000000000001) = 63
}

func ExampleTrailingZeros8() {
	fmt.Printf("TrailingZeros8(%08b) = %d\n", 14, bits.TrailingZeros8(14))
	// Output:
	// TrailingZeros8(00001110) = 1
}

func ExampleTrailingZeros16() {
	fmt.Printf("TrailingZeros16(%016b) = %d\n", 14, bits.TrailingZeros16(14))
	// Output:
	// TrailingZeros16(0000000000001110) = 1
}

func ExampleTrailingZeros32() {
	fmt.Printf("TrailingZeros32(%032b) = %d\n", 14, bits.TrailingZeros32(14))
	// Output:
	// TrailingZeros32(00000000000000000000000000001110) = 1
}

func ExampleTrailingZeros64() {
	fmt.Printf("TrailingZeros64(%064b) = %d\n", 14, bits.TrailingZeros64(14))
	// Output:
	// TrailingZeros64(0000000000000000000000000000000000000000000000000000000000001110) = 1
}

func ExampleOnesCount() {
	fmt.Printf("OnesCount(%b) = %d\n", 14, bits.OnesCount(14))
	// Output:
	// OnesCount(1110) = 3
}

func ExampleOnesCount8() {
	fmt.Printf("OnesCount8(%08b) = %d\n", 14, bits.OnesCount8(14))
	// Output:
	// OnesCount8(00001110) = 3
}

func ExampleOnesCount16() {
	fmt.Printf("OnesCount16(%016b) = %d\n", 14, bits.OnesCount16(14))
	// Output:
	// OnesCount16(0000000000001110) = 3
}

func ExampleOnesCount32() {
	fmt.Printf("OnesCount32(%032b) = %d\n", 14, bits.OnesCount32(14))
	// Output:
	// OnesCount32(00000000000000000000000000001110) = 3
}

func ExampleOnesCount64() {
	fmt.Printf("OnesCount64(%064b) = %d\n", 14, bits.OnesCount64(14))
	// Output:
	// OnesCount64(0000000000000000000000000000000000000000000000000000000000001110) = 3
}

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() {
	fmt.Printf("%08b\n", 19)
	fmt.Printf("%08b\n", bits.Reverse8(19))
	// Output:
	// 00010011
	// 11001000
}

func ExampleReverse16() {
	fmt.Printf("%016b\n", 19)
	fmt.Printf("%016b\n", bits.Reverse16(19))
	// Output:
	// 0000000000010011
	// 1100100000000000
}

func ExampleReverse32() {
	fmt.Printf("%032b\n", 19)
	fmt.Printf("%032b\n", bits.Reverse32(19))
	// Output:
	// 00000000000000000000000000010011
	// 11001000000000000000000000000000
}

func ExampleReverse64() {
	fmt.Printf("%064b\n", 19)
	fmt.Printf("%064b\n", bits.Reverse64(19))
	// Output:
	// 0000000000000000000000000000000000000000000000000000000000010011
	// 1100100000000000000000000000000000000000000000000000000000000000
}

func ExampleReverseBytes16() {
	fmt.Printf("%016b\n", 15)
	fmt.Printf("%016b\n", bits.ReverseBytes16(15))
	// Output:
	// 0000000000001111
	// 0000111100000000
}

func ExampleReverseBytes32() {
	fmt.Printf("%032b\n", 15)
	fmt.Printf("%032b\n", bits.ReverseBytes32(15))
	// Output:
	// 00000000000000000000000000001111
	// 00001111000000000000000000000000
}

func ExampleReverseBytes64() {
	fmt.Printf("%064b\n", 15)
	fmt.Printf("%064b\n", bits.ReverseBytes64(15))
	// Output:
	// 0000000000000000000000000000000000000000000000000000000000001111
	// 0000111100000000000000000000000000000000000000000000000000000000
}

func ExampleLen8() {
	fmt.Printf("Len8(%08b) = %d\n", 8, bits.Len8(8))
	// Output:
	// Len8(00001000) = 4
}

func ExampleLen16() {
	fmt.Printf("Len16(%016b) = %d\n", 8, bits.Len16(8))
	// Output:
	// Len16(0000000000001000) = 4
}

func ExampleLen32() {
	fmt.Printf("Len32(%032b) = %d\n", 8, bits.Len32(8))
	// Output:
	// Len32(00000000000000000000000000001000) = 4
}

func ExampleLen64() {
	fmt.Printf("Len64(%064b) = %d\n", 8, bits.Len64(8))
	// Output:
	// Len64(0000000000000000000000000000000000000000000000000000000000001000) = 4
}