6
6
7
7
** Contract type:** Static library
8
8
9
- The ` Bits ` library is used for working with the individual bits of a ` uint ` .
9
+ ** Source file:** [ Bits.sol] ( ../../src/bits/Bits.sol )
10
+
11
+ ** Example usage:** [ BitsExamples.sol] ( ../../examples/bits/BitsExamples.sol )
12
+
13
+ ** Tests source file:** [ bits_tests.sol] ( ../../test/bits/bits_tests.sol )
14
+
15
+ ** Perf (gas usage) source file:** [ bits_perfs.sol] ( ../../perf/bits/bits_perfs.sol )
10
16
11
- ** Example usage:** [ BitsExamples.sol] ( ../../examples/bits/BitsExamples.sol ) })
17
+
18
+ ## description
19
+
20
+ The ` Bits ` library is used for working with the individual bits of a ` uint ` .
12
21
13
22
## Functions
14
23
15
- - [ setBit(uint, uint8)] ( #setBit )
16
- - [ clearBit(uint, uint8)] ( #clearBit )
17
- - [ toggleBit(uint, uint8)] ( #toggleBit )
18
- - [ bit(uint, uint8)] ( #bit )
19
- - [ bitSet(uint, uint8)] ( #bitSet )
20
- - [ bitEqual(uint, uint, uint8)] ( #bitEqual )
21
- - [ bitAnd(uint, uint, uint8)] ( #bitAnd )
22
- - [ bitOr(uint, uint, uint8)] ( #bitOr )
23
- - [ bitXor(uint, uint, uint8)] ( #bitXor )
24
- - [ bits(uint, uint8, uint16)] ( #bits )
25
- - [ highestBitSet(uint)] ( #highestBitSet )
26
- - [ lowestBitSet(uint)] ( #lowestBitSet )
24
+ - [ setBit(uint, uint8)] ( #setbituint-uint8 )
25
+ - [ clearBit(uint, uint8)] ( #clearbituint-uint8 )
26
+ - [ toggleBit(uint, uint8)] ( #togglebituint-uint8 )
27
+ - [ bit(uint, uint8)] ( #bituint-uint8 )
28
+ - [ bitSet(uint, uint8)] ( #bitsetuint-uint8 )
29
+ - [ bitEqual(uint, uint, uint8)] ( #bitequaluint-uint-uint8 )
30
+ - [ bitAnd(uint, uint, uint8)] ( #bitanduint-uint-uint8 )
31
+ - [ bitOr(uint, uint, uint8)] ( #bitoruint-uint-uint8 )
32
+ - [ bitXor(uint, uint, uint8)] ( #bitxoruint-uint-uint8 )
33
+ - [ bits(uint, uint8, uint16)] ( #bitsuint-uint8-uint16 )
34
+ - [ highestBitSet(uint)] ( #highestbitsetuint )
35
+ - [ lowestBitSet(uint)] ( #lowestbitsetuint )
27
36
28
37
***
29
38
30
- ### < a name = " setBit " /> setBit(uint, uint8)
39
+ ### setBit(uint, uint8)
31
40
32
41
` function setBit(uint, uint8) internal pure returns (uint) `
33
42
@@ -48,11 +57,11 @@ Sets the bit at position `index` to `1`.
48
57
- ` self.setBit(index) >> index & 1 == 1 `
49
58
##### gascosts
50
59
51
- - Fixed: 161
60
+ - Fixed: ** 161**
52
61
53
62
***
54
63
55
- ### < a name = " clearBit " /> clearBit(uint, uint8)
64
+ ### clearBit(uint, uint8)
56
65
57
66
` function clearBit(uint, uint8) internal pure returns (uint) `
58
67
@@ -73,11 +82,11 @@ Sets the bit at position `index` to `0`.
73
82
- ` self.setBit(index) >> index & 1 == 0 `
74
83
##### gascosts
75
84
76
- - Fixed: 164
85
+ - Fixed: ** 164**
77
86
78
87
***
79
88
80
- ### < a name = " toggleBit " /> toggleBit(uint, uint8)
89
+ ### toggleBit(uint, uint8)
81
90
82
91
` function toggleBit(uint, uint8) internal pure returns (uint) `
83
92
@@ -98,11 +107,11 @@ Toggles the bit at position `index`.
98
107
- ` newField = self.toggleBit(index) => newField.bit(index) == 1 - self.bit(index) `
99
108
##### gascosts
100
109
101
- - Fixed: 161
110
+ - Fixed: ** 161**
102
111
103
112
***
104
113
105
- ### < a name = " bit " /> bit(uint, uint8)
114
+ ### bit(uint, uint8)
106
115
107
116
` function bit(uint, uint8) internal pure returns (uint8) `
108
117
@@ -120,11 +129,11 @@ Returns the bit at `index`.
120
129
121
130
##### gascosts
122
131
123
- - Fixed: 164
132
+ - Fixed: ** 164**
124
133
125
134
***
126
135
127
- ### < a name = " bitSet " /> bitSet(uint, uint8)
136
+ ### bitSet(uint, uint8)
128
137
129
138
` function bitSet(uint, uint8) internal pure returns (bool) `
130
139
@@ -142,11 +151,11 @@ Check if the bit at `index` is set.
142
151
143
152
##### gascosts
144
153
145
- - Fixed: 170
154
+ - Fixed: ** 170**
146
155
147
156
***
148
157
149
- ### < a name = " bitEqual " /> bitEqual(uint, uint, uint8)
158
+ ### bitEqual(uint, uint, uint8)
150
159
151
160
` function bitEqual(uint, uint, uint8) internal pure returns (bool) `
152
161
@@ -165,11 +174,11 @@ Checks if the bit at `index` in `self` is the same as the corresponding bit in `
165
174
166
175
##### gascosts
167
176
168
- - Fixed: 184
177
+ - Fixed: ** 184**
169
178
170
179
***
171
180
172
- ### < a name = " bitAnd " /> bitAnd(uint, uint, uint8)
181
+ ### bitAnd(uint, uint, uint8)
173
182
174
183
` function bitAnd(uint, uint, uint8) internal pure returns (uint8) `
175
184
@@ -188,11 +197,11 @@ Calculates the bitwise `AND` of the bit at position `index` in `self` and the co
188
197
189
198
##### gascosts
190
199
191
- - Fixed: 178
200
+ - Fixed: ** 178**
192
201
193
202
***
194
203
195
- ### < a name = " bitOr " /> bitOr(uint, uint, uint8)
204
+ ### bitOr(uint, uint, uint8)
196
205
197
206
` function bitOr(uint, uint, uint8) internal pure returns (uint8) `
198
207
@@ -211,11 +220,11 @@ Calculates the bitwise `OR` of the bit at position `index` in `self` and the cor
211
220
212
221
##### gascosts
213
222
214
- - Fixed: 178
223
+ - Fixed: ** 178**
215
224
216
225
***
217
226
218
- ### < a name = " bitXor " /> bitXor(uint, uint, uint8)
227
+ ### bitXor(uint, uint, uint8)
219
228
220
229
` function bitXor(uint, uint, uint8) internal pure returns (uint8) `
221
230
@@ -234,11 +243,11 @@ Calculates the bitwise `XOR` of the bit at position `index` in `self` and the co
234
243
235
244
##### gascosts
236
245
237
- - Fixed: 178
246
+ - Fixed: ** 178**
238
247
239
248
***
240
249
241
- ### < a name = " bits " /> bits(uint, uint8, uint16)
250
+ ### bits(uint, uint8, uint16)
242
251
243
252
` function bits(uint, uint8, uint16) internal pure returns (uint) `
244
253
@@ -264,11 +273,11 @@ To get all the bits: `self.bits(0, 256)`
264
273
265
274
##### gascosts
266
275
267
- - Fixed: 330
276
+ - Fixed: ** 385 **
268
277
269
278
***
270
279
271
- ### < a name = " highestBitSet " /> highestBitSet(uint)
280
+ ### highestBitSet(uint)
272
281
273
282
` function highestBitSet(uint) internal pure returns (uint8) `
274
283
@@ -288,12 +297,12 @@ Calculates the index of the highest bit set in `self`.
288
297
289
298
##### gascosts
290
299
291
- - For highest bit set == 0: 2845
292
- - For highest bit set == 31: 3759
300
+ - For highest bit set == 0: ** 2845**
301
+ - For highest bit set == 31: ** 3759**
293
302
294
303
***
295
304
296
- ### < a name = " lowestBitSet " /> lowestBitSet(uint)
305
+ ### lowestBitSet(uint)
297
306
298
307
` function lowestBitSet(uint) internal pure returns (uint8) `
299
308
@@ -313,6 +322,6 @@ Calculates the index of the lowest bit set in `self`.
313
322
314
323
##### gascosts
315
324
316
- - For lowest bit set == 0: 2181
317
- - For lowest bit set == 31: 3095
325
+ - For lowest bit set == 0: ** 2181**
326
+ - For lowest bit set == 31: ** 3095**
318
327
0 commit comments