efficient bit manipulation of memory
I have a large chunk of memory that I want to bit-wise complement. Since I want it to be fast, I don't really want to go byte by byte. What's the best way to do this?
Here's a first implementation using longs, but I want to do a bigger chunk at a time. However I'm worried that doing a larger chunk might be dependent on the word size of the machine.
Code:
char *memory = 0xblahblahblah;
unsigned int size = a zillion;
int i;
for (i = 0; i < size; i+=sizeof(unsigned long))
{
*((unsigned long *)(memory + i)) = ~(*((unsigned long *)(memory + i)));
}