bfix has two routines for insertion(bfi()) and extraction(bfx()) of bit fields in data of arbitrary length. It can be compiled with little/big endian or have run timechecking. It is 32/64 bit safe.