extra-bit 2.1.1 → 2.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -16
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,17 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
This package includes [bit twiddling hacks] by Sean Eron Anderson and many others.<br>
|
|
1
|
+
A collection of common bitwise operations.<br>
|
|
3
2
|
📦 [Node.js](https://www.npmjs.com/package/extra-bit),
|
|
4
3
|
🌐 [Web](https://www.npmjs.com/package/extra-bit.web),
|
|
5
4
|
📜 [Files](https://unpkg.com/extra-bit/),
|
|
6
5
|
📰 [Docs](https://nodef.github.io/extra-bit/).
|
|
7
6
|
📘 [Wiki](https://github.com/nodef/extra-bit/wiki/).
|
|
8
7
|
|
|
8
|
+
The [bit] is a basic unit of information in information theory, computing. This
|
|
9
|
+
package includes [bit twiddling hacks] by *Sean Eron Anderson* and many others.
|
|
10
|
+
JavaScript converts a `Number` (a *64-bit floating point number*) to a *32-bit*
|
|
11
|
+
*integer* when bitwise operators (such as `|`) are applied. All bitwise operations
|
|
12
|
+
are performed on **32-bit integers**.
|
|
13
|
+
|
|
9
14
|
This package is available in *Node.js* and *Web* formats. The web format
|
|
10
15
|
is exposed as `extra_bit` standalone variable and can be loaded from
|
|
11
16
|
[jsDelivr CDN].
|
|
12
17
|
|
|
13
18
|
> Stability: [Experimental](https://www.youtube.com/watch?v=L1j93RnIxEo).
|
|
14
19
|
|
|
20
|
+
[bit]: https://en.wikipedia.org/wiki/Bit
|
|
21
|
+
[bit twiddling hacks]: https://graphics.stanford.edu/~seander/bithacks.html
|
|
15
22
|
[jsDelivr CDN]: https://cdn.jsdelivr.net/npm/extra-bit.web/index.js
|
|
16
23
|
|
|
17
24
|
<br>
|
|
@@ -19,22 +26,22 @@ is exposed as `extra_bit` standalone variable and can be loaded from
|
|
|
19
26
|
```javascript
|
|
20
27
|
const bit = require('extra-bit');
|
|
21
28
|
// import * as bit from "extra-bit";
|
|
22
|
-
// import * as bit from "https://unpkg.com/extra-bit
|
|
29
|
+
// import * as bit from "https://unpkg.com/extra-bit/index.mjs"; (deno)
|
|
23
30
|
|
|
24
31
|
bit.count(7);
|
|
25
|
-
// 3 (111 ⇒ 3)
|
|
32
|
+
// → 3 (111 ⇒ 3)
|
|
26
33
|
|
|
27
34
|
bit.parity(8, 2);
|
|
28
|
-
// 2 (10,00 ⇒ 10)
|
|
35
|
+
// → 2 (10,00 ⇒ 10)
|
|
29
36
|
|
|
30
37
|
bit.swap(6, 1, 0);
|
|
31
|
-
// 5 (110 ⇒ 101)
|
|
38
|
+
// → 5 (110 ⇒ 101)
|
|
32
39
|
|
|
33
40
|
bit.reverse(0xFFFF0000);
|
|
34
|
-
// 65535 (0x0000FFFF)
|
|
41
|
+
// → 65535 (0x0000FFFF)
|
|
35
42
|
|
|
36
43
|
bit.signExtend(15, 4);
|
|
37
|
-
// -1
|
|
44
|
+
// → -1
|
|
38
45
|
```
|
|
39
46
|
|
|
40
47
|
<br>
|
|
@@ -45,18 +52,18 @@ bit.signExtend(15, 4);
|
|
|
45
52
|
|
|
46
53
|
| Property | Description |
|
|
47
54
|
| ---- | ---- |
|
|
48
|
-
| [get] | Get
|
|
55
|
+
| [get] | Get bits at specified index. |
|
|
49
56
|
| [getAs] | Get bits as per mask. |
|
|
50
|
-
| [set] | Set
|
|
57
|
+
| [set] | Set bits at specified index. |
|
|
51
58
|
| [setAs] | Set bits as per mask. |
|
|
52
|
-
| [toggle] | Toggle
|
|
59
|
+
| [toggle] | Toggle bits at specified index. |
|
|
53
60
|
| [toggleAs] | Toggle bits as per mask. |
|
|
54
|
-
| [swap] | Swap bit sequences. |
|
|
61
|
+
| [swap] | Swap bit sequences at specified indices. |
|
|
55
62
|
| [scan] | Find index of first set bit from LSB. |
|
|
56
63
|
| [scanReverse] | Find index of first set bit from MSB. |
|
|
57
64
|
| [count] | Count bits set. |
|
|
58
|
-
| [parity] |
|
|
59
|
-
| [rotate] | Rotate bits. |
|
|
65
|
+
| [parity] | Calculate n-bit parity. |
|
|
66
|
+
| [rotate] | Rotate bits by a certain amount. |
|
|
60
67
|
| [reverse] | Reverse all bits. |
|
|
61
68
|
| [merge] | Merge bits as per mask. |
|
|
62
69
|
| [interleave] | Interleave bits of two int16s. |
|
|
@@ -65,10 +72,10 @@ bit.signExtend(15, 4);
|
|
|
65
72
|
<br>
|
|
66
73
|
<br>
|
|
67
74
|
|
|
75
|
+
|
|
68
76
|
[](https://www.youtube.com/watch?v=4Yy0pPTrHlk)
|
|
69
77
|
|
|
70
|
-
|
|
71
|
-
[bit twiddling hacks]: https://graphics.stanford.edu/~seander/bithacks.html
|
|
78
|
+
|
|
72
79
|
[get]: https://nodef.github.io/extra-bit/modules.html#get
|
|
73
80
|
[getAs]: https://nodef.github.io/extra-bit/modules.html#getAs
|
|
74
81
|
[set]: https://nodef.github.io/extra-bit/modules.html#set
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "extra-bit",
|
|
3
|
-
"version": "2.1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "2.1.4",
|
|
4
|
+
"description": "A collection of common bitwise operations.",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"module": "index.mjs",
|