Source code for low level binary functions


some bit wizardry from FXT

*** There is a bit wizardry chapter in the fxtbook ***

Everything here is taken from the FXT library (see the fxtpage). You'll find the files in the directory bits/.

Many of the files #include
bitsperlong.h which #defines BITS_PER_LONG according to the sizeof(long).
The type 'unsigned long' is abbreviated 'ulong' throughout, this is done in fxttypes.h:
typedef unsigned long ulong;


bitcount.h (population count: counting the bits in a word)
bitlow.h (functions that isolate/find the lowest set bit)
bitlow-edge.h (create 10 or 01 edge at the lowest set bit)
bithigh.h (functions that isolate/find the highest set bit)
bithigh-edge.h (create 10 or 01 edge at the highest set bit)
bit2pow.h (functions like floor(log2()))
bitzip.h (even/odd bits to/from low/high bits)
bitbutterfly.h (aux for bit-zip)
bitrotate.h (rotating words)
bitasm-i386.h (i386 inline asm versions of various functions)
bitasm-amd64.h (AMD64 inline asm versions of various functions)
bitsubsetq.h (return whether a word is a bit-subset of another word)
bitsubset.h (generate all bit-subsets of a word)
bitsubset-gray.h (all bit-subsets of a word, Gray code order)
ith-one-idx.h (index of the i-th set bit in a word)
bittest.h (testing and changing bits of a word)
bitcopy.h (copying bits of a word)
bitswap.h (swapping groups of bits)
revbin.h (reversing the order of bits in a word)
revbin-upd.h (counting in bit-reversed order)
branchless.h (code that avoids branches)
graycode.h (graycode and its inverse)
parity.h (parity)
evenodd.h () (next_even(), next_odd() etc.)
zerobyte.h (finding zero bytes in a word)
tinyfactors.h (determining whether d divides x for d,x<BITS_PER_LONG)
generated index of all headers

Slightly esoteric stuff:
bit2adic.h (2-adic inverse and square root)
bitgather.h (bit gather/scatter)
bitseparate.h (separate bits according to a mask)
bitcombcolex.h (generate bit-combinations in colex order)
bitcombcolex.h (generate bit-combinations in colex order)
bitcombminchange.h (generate words with a given number of set bits with minimal changes between words)
parenwords.h (determine whether binary word corresponds to a well-formed parenthesizing)
hilbert.h (1dim coord. to 2dim hilbert coord.)
zorder.h (1dim coord. to 2dim/3dim space filling curve, Z-order)
bit-paper-fold.h (paper-folding sequence, also turns of the dragon curve)
bit-dragon3.h (turns of the terdragon curve)
bitsequency.h (generate words with given number of edges)
grsnegative.h (whether Golay-Rudin-Shapiro sequence negative at an index)
bitlex.h (generate bit sets in lex order)
bitcyclic-minmax.h (min and max among bitwise rotations)
bitcyclic-period.h (periodicity of bitwise rotations)
bitcyclic-dist.h (distance among bitwise rotations)
bitcyclic-match.h (matching bitwise rotations)
bitcyclic-xor.h (rotate-xor operation and its inverse)
bitperiodic.h (creating a periodic word)
cswap.h (conditional swap)
bit-necklace.h (generate all binary necklaces)
bitmrotate.h (modular bit-rotations)
revgraycode.h (reversed Gray code)
graypower.h (Gray code powered)
bittransforms.h (invertible transforms of binary words: blue-, yellow-, cyan-, and red code)
blue-fixed-points.h (fixed points fo the blue code)
bitxtransforms.h (invertible transforms Kronecker-powered)
negbin.h (conversion from and to radix -2)
bin2naf.h (non-adjacent form: sparse signed binary representation)
bitblock.h (generating a bit block)
bitfibgray (Gray code for the Fibonacci words)
crc64.h Cyclic Redundancy Check (CRC), 64 bit
crc32.h Cyclic Redundancy Check (CRC), 32 bit
tcrc64.h CRC with lookup table, 64 bit
pcrc64.h parallel CRC, 64 bit
fibrep.h Fibonacci representations
colormix.h (functions that add/average/multiply/mix color channels)
colormixp.h (versions of some of the above funcs that are correct to the last bit)
colormix-fl.h (color manipulation with floating point args)
bit-isolate.h (isolation of bits/blocks at low and high end, and at 0/1 and 1/0 transitions)
bit-necklace.h (generate all binary necklaces)
bitcombshifts.h (genrate all combinations in shifts order)
revgraycode.h (reversed Gray code and its inverse)
thue-morse.h (Thue-Morse sequence)


Your feedback is appreciated.
jj (Jörg Arndt)

Last modified 2009-July-26 (11:15)
Goto jj's ugly Homepage