Skip to content

elmw/extra-bit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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


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.


References