6
6
/**
7
7
* The bit is a basic unit of information in information theory, computing.
8
8
* This package includes bit twiddling hacks by Sean Eron Anderson and many
9
- * others.
9
+ * others.<br>
10
+ * 📦 <a href="https://search.maven.org/artifact/io.github.javaf/extra-bit">Central</a>,
11
+ * 📜 <a href="https://repo1.maven.org/maven2/io/github/javaf/extra-bit/">Releases</a>,
12
+ * 😺 <a href="https://github.com/javaf/hello-world/packages/579834">GitHub</a>,
13
+ * 🐸 <a href="https://bintray.com/beta/#/bintray/jcenter/io.github.javaf:extra-bit">Bintray</a>,
14
+ * 🦚 <a href="https://mvnrepository.com/artifact/io.github.javaf/extra-bit">MvnRepository</a>,
15
+ * 📰 <a href="https://javaf.github.io/extra-bit/">Javadoc</a>,
16
+ * 📘 <a href="https://github.com/javaf/extra-bit/wiki">Wiki</a>.
10
17
*/
11
18
public final class Bit {
12
19
@@ -27,6 +34,7 @@ public final class Bit {
27
34
// GET*, SET*, TOGGLE*, SWAP
28
35
/**
29
36
* Get a bit.
37
+ * <a href="https://github.com/javaf/extra-boolean/wiki/get">📘</a>
30
38
* @param x an int
31
39
* @param i bit index
32
40
* @return bit
@@ -37,6 +45,7 @@ public static int get(int x, int i) {
37
45
38
46
/**
39
47
* Get a bit.
48
+ * <a href="https://github.com/javaf/extra-boolean/wiki/get">📘</a>
40
49
* @param x a long
41
50
* @param i bit index
42
51
* @return bit
@@ -49,6 +58,7 @@ public static int get(long x, int i) {
49
58
50
59
/**
51
60
* Get bits as per mask.
61
+ * <a href="https://github.com/javaf/extra-boolean/wiki/getAs">📘</a>
52
62
* @param x an int
53
63
* @param m bit mask
54
64
* @return bits
@@ -59,6 +69,7 @@ public static int getAs(int x, int m) {
59
69
60
70
/**
61
71
* Get bits as per mask.
72
+ * <a href="https://github.com/javaf/extra-boolean/wiki/getAs">📘</a>
62
73
* @param x a long
63
74
* @param m bit mask
64
75
* @return bits
@@ -71,6 +82,7 @@ public static long getAs(long x, long m) {
71
82
72
83
/**
73
84
* Set a bit.
85
+ * <a href="https://github.com/javaf/extra-boolean/wiki/set">📘</a>
74
86
* @param x an int
75
87
* @param i bit index
76
88
* @param f bit value (1)
@@ -82,6 +94,7 @@ public static int set(int x, int i, int f) {
82
94
83
95
/**
84
96
* Set a bit.
97
+ * <a href="https://github.com/javaf/extra-boolean/wiki/set">📘</a>
85
98
* @param x a long
86
99
* @param i bit index
87
100
* @param f bit value (1)
@@ -95,6 +108,7 @@ public static long set(long x, int i, int f) {
95
108
96
109
/**
97
110
* Set bits as per mask.
111
+ * <a href="https://github.com/javaf/extra-boolean/wiki/setAs">📘</a>
98
112
* @param x an int
99
113
* @param m bit mask
100
114
* @param f bit value (1)
@@ -106,6 +120,7 @@ public static int setAs(int x, int m, int f) {
106
120
107
121
/**
108
122
* Set bits as per mask.
123
+ * <a href="https://github.com/javaf/extra-boolean/wiki/setAs">📘</a>
109
124
* @param x a long
110
125
* @param m bit mask
111
126
* @param f bit value (1)
@@ -119,6 +134,7 @@ public static long setAs(long x, long m, int f) {
119
134
120
135
/**
121
136
* Toggle a bit.
137
+ * <a href="https://github.com/javaf/extra-boolean/wiki/toggle">📘</a>
122
138
* @param x an int
123
139
* @param i bit index
124
140
* @return toggled int
@@ -129,6 +145,7 @@ public static int toggle(int x, int i) {
129
145
130
146
/**
131
147
* Toggle a bit.
148
+ * <a href="https://github.com/javaf/extra-boolean/wiki/toggle">📘</a>
132
149
* @param x a long
133
150
* @param i bit index
134
151
* @return toggled long
@@ -141,6 +158,7 @@ public static long toggle(long x, int i) {
141
158
142
159
/**
143
160
* Toggle bits as per mask.
161
+ * <a href="https://github.com/javaf/extra-boolean/wiki/toggleAs">📘</a>
144
162
* @param x an int
145
163
* @param m bit mask
146
164
* @return toggled int
@@ -151,6 +169,7 @@ public static int toggleAs(int x, int m) {
151
169
152
170
/**
153
171
* Toggle bits as per mask.
172
+ * <a href="https://github.com/javaf/extra-boolean/wiki/toggleAs">📘</a>
154
173
* @param x a long
155
174
* @param m bit mask
156
175
* @return toggled long
@@ -163,6 +182,7 @@ public static long toggleAs(long x, long m) {
163
182
164
183
/**
165
184
* Swap bits.
185
+ * <a href="https://github.com/javaf/extra-boolean/wiki/swap">📘</a>
166
186
* @param x an int
167
187
* @param i first bit index
168
188
* @param j second bit index
@@ -175,6 +195,7 @@ public static int swap(int x, int i, int j) {
175
195
176
196
/**
177
197
* Swap bits.
198
+ * <a href="https://github.com/javaf/extra-boolean/wiki/swap">📘</a>
178
199
* @param x a long
179
200
* @param i first bit index
180
201
* @param j second bit index
@@ -187,6 +208,7 @@ public static long swap(long x, int i, int j) {
187
208
188
209
/**
189
210
* Swap bit sequences.
211
+ * <a href="https://github.com/javaf/extra-boolean/wiki/swap">📘</a>
190
212
* @param x an int
191
213
* @param i first bit index
192
214
* @param j second bit index
@@ -200,6 +222,7 @@ public static int swap(int x, int i, int j, int n) {
200
222
201
223
/**
202
224
* Swap bit sequences.
225
+ * <a href="https://github.com/javaf/extra-boolean/wiki/swap">📘</a>
203
226
* @param x a long
204
227
* @param i first bit index
205
228
* @param j second bit index
@@ -217,6 +240,7 @@ public static long swap(long x, int i, int j, int n) {
217
240
// COUNT, PARITY, SCAN*
218
241
/**
219
242
* Count bits set.
243
+ * <a href="https://github.com/javaf/extra-boolean/wiki/count">📘</a>
220
244
* @param x an int
221
245
* @return count
222
246
*/
@@ -228,6 +252,7 @@ public static int count(int x) {
228
252
229
253
/**
230
254
* Count bits set.
255
+ * <a href="https://github.com/javaf/extra-boolean/wiki/count">📘</a>
231
256
* @param x a long
232
257
* @return count
233
258
*/
@@ -242,6 +267,7 @@ public static int count(long x) {
242
267
243
268
/**
244
269
* Get 1-bit parity.
270
+ * <a href="https://github.com/javaf/extra-boolean/wiki/parity">📘</a>
245
271
* @param x an int
246
272
* @return parity
247
273
*/
@@ -255,6 +281,7 @@ public static int parity(int x) {
255
281
256
282
/**
257
283
* Get 1-bit parity.
284
+ * <a href="https://github.com/javaf/extra-boolean/wiki/parity">📘</a>
258
285
* @param x a long
259
286
* @return parity
260
287
*/
@@ -269,6 +296,7 @@ public static int parity(long x) {
269
296
270
297
/**
271
298
* Get n-bit parity.
299
+ * <a href="https://github.com/javaf/extra-boolean/wiki/parity">📘</a>
272
300
* @param x an int
273
301
* @param n number of bits (1)
274
302
* @return parity
@@ -285,6 +313,7 @@ public static int parity(int x, int n) {
285
313
286
314
/**
287
315
* Get n-bit parity.
316
+ * <a href="https://github.com/javaf/extra-boolean/wiki/parity">📘</a>
288
317
* @param x an int
289
318
* @param n number of bits (1)
290
319
* @return parity
@@ -303,6 +332,7 @@ public static int parity(long x, int n) {
303
332
304
333
/**
305
334
* Get index of first set bit from LSB.
335
+ * <a href="https://github.com/javaf/extra-boolean/wiki/scan">📘</a>
306
336
* @param x an int
307
337
* @return bit index
308
338
*/
@@ -312,6 +342,7 @@ public static int scan(int x) {
312
342
313
343
/**
314
344
* Get index of first set bit from LSB.
345
+ * <a href="https://github.com/javaf/extra-boolean/wiki/scan">📘</a>
315
346
* @param x a long
316
347
* @return bit index
317
348
*/
@@ -325,6 +356,7 @@ public static int scan(long x) {
325
356
326
357
/**
327
358
* Get index of first set bit from MSB.
359
+ * <a href="https://github.com/javaf/extra-boolean/wiki/scanReverse">📘</a>
328
360
* @param x an int32
329
361
* @return bit index
330
362
*/
@@ -339,6 +371,7 @@ public static int scanReverse(int x) {
339
371
340
372
/**
341
373
* Get index of first set bit from LSB.
374
+ * <a href="https://github.com/javaf/extra-boolean/wiki/scanReverse">📘</a>
342
375
* @param x a long
343
376
* @return bit index
344
377
*/
@@ -354,6 +387,7 @@ public static int scanReverse(long x) {
354
387
// MERGE, INTERLEAVE, ROTATE, REVERSE, SIGNEXTEND
355
388
/**
356
389
* Merge bits as per mask.
390
+ * <a href="https://github.com/javaf/extra-boolean/wiki/merge">📘</a>
357
391
* @param x first int
358
392
* @param y second int
359
393
* @param m bit mask (0 ⇒ from x)
@@ -365,6 +399,7 @@ public static int merge(int x, int y, int m) {
365
399
366
400
/**
367
401
* Merge bits as per mask.
402
+ * <a href="https://github.com/javaf/extra-boolean/wiki/merge">📘</a>
368
403
* @param x first long
369
404
* @param y second long
370
405
* @param m bit mask (0 ⇒ from x)
@@ -378,6 +413,7 @@ public static long merge(long x, long y, long m) {
378
413
379
414
/**
380
415
* Interleave bits of two shorts.
416
+ * <a href="https://github.com/javaf/extra-boolean/wiki/interleave">📘</a>
381
417
* @param x first short
382
418
* @param y second short
383
419
* @return int
@@ -396,6 +432,7 @@ public static int interleave(int x, int y) {
396
432
397
433
/**
398
434
* Interleave bits of two ints.
435
+ * <a href="https://github.com/javaf/extra-boolean/wiki/interleave">📘</a>
399
436
* @param x first int
400
437
* @param y second int
401
438
* @return interleaved long
@@ -418,6 +455,7 @@ public static long interleave(long x, long y) {
418
455
419
456
/**
420
457
* Rotate bits.
458
+ * <a href="https://github.com/javaf/extra-boolean/wiki/rotate">📘</a>
421
459
* @param x an int
422
460
* @param n rotate amount (+ve: left, -ve: right)
423
461
* @return rotated int
@@ -428,6 +466,7 @@ public static int rotate(int x, int n) {
428
466
429
467
/**
430
468
* Rotate bits.
469
+ * <a href="https://github.com/javaf/extra-boolean/wiki/rotate">📘</a>
431
470
* @param x a long
432
471
* @param n rotate amount (+ve: left, -ve: right)
433
472
* @return rotated long
@@ -440,6 +479,7 @@ public static long rotate(long x, int n) {
440
479
441
480
/**
442
481
* Reverse all bits.
482
+ * <a href="https://github.com/javaf/extra-boolean/wiki/reverse">📘</a>
443
483
* @param x an int
444
484
* @return reversed int
445
485
*/
@@ -453,6 +493,7 @@ public static int reverse(int x) {
453
493
454
494
/**
455
495
* Reverse all bits.
496
+ * <a href="https://github.com/javaf/extra-boolean/wiki/reverse">📘</a>
456
497
* @param x a long
457
498
* @return reversed long
458
499
*/
@@ -469,6 +510,7 @@ public static long reverse(long x) {
469
510
470
511
/**
471
512
* Sign extend variable bit-width integer.
513
+ * <a href="https://github.com/javaf/extra-boolean/wiki/signExtend">📘</a>
472
514
* @param x variable bit-width int
473
515
* @param w bit width (32)
474
516
* @return sign-extended int
@@ -480,6 +522,7 @@ public static int signExtend(int x, int w) {
480
522
481
523
/**
482
524
* Sign extend variable bit-width integer.
525
+ * <a href="https://github.com/javaf/extra-boolean/wiki/signExtend">📘</a>
483
526
* @param x variable bit-width long
484
527
* @param w bit width (64)
485
528
* @return sign-extended long
0 commit comments