Reputation: 681
How can I flip any bit I want in a chunk of memory:
int size = 4000;
void* block = malloc(size);
bzero(block, size);
// flip bit #100 in block
Thanks
Upvotes: 0
Views: 270
Reputation: 182753
void flip_bit (void *block, int bit)
{
unsigned char *b = (unsigned char *) block;
b[bit/8] ^= 1 << (bit % 8);
}
Upvotes: 1