The bit is a basic unit of information in information theory, computing.
📦 Package,
:blue_book: Wiki.
This package includes bit twiddling hacks by Sean Eron Anderson and many others.
Stability: Experimental.
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
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. |
- Bit, Nibble, Byte, Word
- Kilobit, Kilobyte, Kibibit, Kibibyte
- Bit field, Bit array, Bitwise operation, Mask
- Bit manipulation, Bit manipulation instruction set, Bit banging