https://github.com/nodef/extra-bit.java
The bit is a basic unit of information in information theory, computing.
https://github.com/nodef/extra-bit.java
arithmetic bit bitwise count extend extra interleave java maven merge operations operators parity reverse rotate scan sign swap toggle
Last synced: 5 months ago
JSON representation
The bit is a basic unit of information in information theory, computing.
- Host: GitHub
- URL: https://github.com/nodef/extra-bit.java
- Owner: nodef
- License: mit
- Created: 2020-10-07T12:20:23.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2025-04-10T20:05:01.000Z (9 months ago)
- Last Synced: 2025-07-23T05:48:28.042Z (6 months ago)
- Topics: arithmetic, bit, bitwise, count, extend, extra, interleave, java, maven, merge, operations, operators, parity, reverse, rotate, scan, sign, swap, toggle
- Language: Java
- Homepage: https://search.maven.org/artifact/io.github.javaf/extra-bit
- Size: 524 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
The [bit] is a basic unit of information in information theory, computing.
:package: [Central](https://search.maven.org/artifact/io.github.javaf/extra-bit),
:scroll: [Releases](https://repo1.maven.org/maven2/io/github/javaf/extra-bit/),
:octocat: [GitHub](https://github.com/javaf/hello-world/packages/575247),
:frog: [Bintray](https://bintray.com/beta/#/bintray/jcenter/io.github.javaf:extra-bit),
:peacock: [MvnRepository](https://mvnrepository.com/artifact/io.github.javaf/extra-bit),
:newspaper: [Javadoc](https://javaf.github.io/extra-bit/)
:blue_book: [Wiki](https://github.com/javaf/extra-bit/wiki).
This package includes [bit twiddling hacks] by Sean Eron Anderson and many others.
> Stability: Experimental.
[bit]: https://en.wikipedia.org/wiki/Bit
[bit twiddling hacks]: https://graphics.stanford.edu/~seander/bithacks.html
```java
import io.github.javaf.*;
Bit.count(7);
// 3 (111 ⇒ 3)
Bit.parity(8, 2);
// 2 (10,00 ⇒ 10)
Bit.swap(6, 1, 0);
// 5 (110 ⇒ 101)
Bit.reverse(0xFFFF0000);
// 65535 (0x0000FFFF)
Bit.signExtend(15, 4);
// -1
```
## Index
| Method | Action |
| ------------ | --------------------------------------- |
| [get] | Get a bit. |
| [set] | Set a bit. |
| [toggle] | Toggle a bit. |
| [swap] | Swap bit sequences. |
| [scan] | Get index of first set bit from LSB. |
| [count] | Count bits set. |
| [parity] | Get n-bit parity. |
| [rotate] | Rotate bits. |
| [reverse] | Reverse all bits. |
| [merge] | Merge bits as per mask. |
| [interleave] | Interleave bits of two int16s. |
| [signExtend] | Sign extend variable bit-width integer. |
[get]: https://github.com/javaf/extra-bit/wiki/get
[set]: https://github.com/javaf/extra-bit/wiki/set
[setAs]: https://github.com/javaf/extra-bit/wiki/setAs
[swap]: https://github.com/javaf/extra-bit/wiki/swap
[scan]: https://github.com/javaf/extra-bit/wiki/scan
[scanReverse]: https://github.com/javaf/extra-bit/wiki/scanReverse
[count]: https://github.com/javaf/extra-bit/wiki/count
[parity]: https://github.com/javaf/extra-bit/wiki/parity
[reverse]: https://github.com/javaf/extra-bit/wiki/reverse
[merge]: https://github.com/javaf/extra-bit/wiki/merge
[interleave]: https://github.com/javaf/extra-bit/wiki/interleave
[signExtend]: https://github.com/javaf/extra-bit/wiki/signExtend
[toggle]: https://github.com/javaf/extra-bit/wiki/toggle
[rotate]: https://github.com/javaf/extra-bit/wiki/rotate
[](https://www.youtube.com/watch?v=r3QQ6dm64xg)

