Skip to content

javaf/extra-bit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

The bit is a basic unit of information in information theory, computing.
📦 Central, :scroll: Releases, :octocat: GitHub, :frog: Bintray, :peacock: MvnRepository, :newspaper: Javadoc 📘 Wiki.


This package includes bit twiddling hacks by Sean Eron Anderson and many others.

Stability: Experimental.


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.