Bit Manipulation

Photo by Erol Ahmed on Unsplash

Bit Manipulation

·

1 min read

Specify a certain bit 1

x |= (1 << y);

Specify a certain bit 0

x &= ~(1 << y);

Specify the reverse of a certain bit

x ^= (1 << y);

Get the value from a certain bit

((x >> y) & 1);