Does anyone know a good bit manipulation library for ANSI C? What I basically need is the ability, as in Jovial , to set certain bits in a variable, something like
int a = 0x123;
setBits(&a,2,5, 0xFF);
printf("0x%x");
int a = 0x123;
printf("0x%x",getBits(&a,2,5));
char a[] = {0xCC, 0xBB};
char b[] = {0x11, 0x12};
copyBits(a,4,b,,4,8);
There, a similar library is called bitfile , but it does not seem to support direct memory manipulation. It only supports feeding bits to file streams.
It is not difficult to write, but if something is tested, I will not reinvent the wheel.
Perhaps this library exists as part of a larger library ( bzip2, gzipare the usual suspects)?
source
share