https://github.com/nodef/extra-bit.elm
The bit is a basic unit of information in information theory, computing.
https://github.com/nodef/extra-bit.elm
arithmetic bit bitwise count elm extend extra interleave merge operations operators parity reverse rotate scan sign swap toggle
Last synced: about 1 month ago
JSON representation
The bit is a basic unit of information in information theory, computing.
- Host: GitHub
- URL: https://github.com/nodef/extra-bit.elm
- Owner: nodef
- License: mit
- Created: 2021-01-15T18:31:45.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2025-04-10T20:05:22.000Z (9 months ago)
- Last Synced: 2025-04-10T21:21:05.460Z (9 months ago)
- Topics: arithmetic, bit, bitwise, count, elm, extend, extra, interleave, merge, operations, operators, parity, reverse, rotate, scan, sign, swap, toggle
- Language: Elm
- Homepage: https://package.elm-lang.org/packages/elmw/extra-bit/latest/
- Size: 26.4 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- 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: [Package](https://package.elm-lang.org/packages/elmw/extra-bit/latest/),
:blue_book: [Wiki](https://github.com/elmw/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
```elm
import Bit exposing (..)
count 7
-- 3 (111 ⇒ 3)
parity 8 2
-- 2 (10,00 ⇒ 10)
swap 6 1 0 1
-- 5 (110 ⇒ 101)
reverse 0xFFFF0000
-- 65535 (0x0000FFFF)
signExtend 15 4
-- -1
```
## Index
| Method | Action |
| ------------ | --------------------------------------- |
| [get] | Get a bit. |
| [set] | Set a bit. |
| [toggle] | Toggle a bit. |
| [swap] | Swap bit sequences. |
| [count] | Count bits set. |
| [parity] | Get n-bit parity. |
| [scan] | Get index of first set bit from LSB. |
| [merge] | Merge bits as per mask. |
| [interleave] | Interleave bits of two int16s. |
| [rotate] | Rotate bits. |
| [reverse] | Reverse all bits. |
| [signExtend] | Sign extend variable bit-width integer. |
[get]: https://github.com/elmw/extra-bit/wiki/get
[set]: https://github.com/elmw/extra-bit/wiki/set
[toggle]: https://github.com/elmw/extra-bit/wiki/toggle
[swap]: https://github.com/elmw/extra-bit/wiki/swap
[count]: https://github.com/elmw/extra-bit/wiki/count
[parity]: https://github.com/elmw/extra-bit/wiki/parity
[scan]: https://github.com/elmw/extra-bit/wiki/scan
[merge]: https://github.com/elmw/extra-bit/wiki/merge
[interleave]: https://github.com/elmw/extra-bit/wiki/interleave
[rotate]: https://github.com/elmw/extra-bit/wiki/rotate
[reverse]: https://github.com/elmw/extra-bit/wiki/reverse
[signExtend]: https://github.com/elmw/extra-bit/wiki/signExtend
## References
- [Bit], [Nibble], [Byte], [Word]
- [Kilobit], [Kilobyte], [Kibibit], [Kibibyte]
- [Bit field], [Bit array], [Bitwise operation], [Mask]
- [Bit manipulation], [Bit manipulation instruction set], [Bit banging]
[Bit]: https://en.wikipedia.org/wiki/Bit
[Nibble]: https://en.wikipedia.org/wiki/Nibble
[Byte]: https://en.wikipedia.org/wiki/Byte
[Word]: https://en.wikipedia.org/wiki/Word_(computer_architecture)
[Kilobit]: https://en.wikipedia.org/wiki/Kilobit
[Kilobyte]: https://en.wikipedia.org/wiki/Kilobyte
[Kibibit]: https://en.wikipedia.org/wiki/Kibibit
[Kibibyte]: https://en.wikipedia.org/wiki/Kibibyte
[Bit field]: https://en.wikipedia.org/wiki/Bit_field
[Bit array]: https://en.wikipedia.org/wiki/Bit_array
[Bitwise operation]: https://en.wikipedia.org/wiki/Bitwise_operation
[Mask]: https://en.wikipedia.org/wiki/Mask_(computing)
[Bit manipulation]: https://en.wikipedia.org/wiki/Bit_manipulation
[Bit manipulation instruction set]: https://en.wikipedia.org/wiki/Bit_manipulation_instruction_set
[Bit banging]: https://en.wikipedia.org/wiki/Bit_banging
[](https://www.youtube.com/watch?v=4_zSIXb7tLQ)
