c-exercises/bit-fuckery.c
2013-06-09 20:56:25 +02:00

33 lines
493 B
C

#include <assert.h>
int main() {
int foo;
foo = 42;
/* Delete bit 5 */
foo &= ~(1 << 5);
assert(foo == 10);
foo &= ~(1 << 5);
assert(foo == 10);
/* Set bit 5 again */
foo |= (1 << 5);
assert(foo == 42);
foo |= (1 << 5);
assert(foo == 42);
/* Set bit 0 */
foo |= (1 << 0);
assert(foo == 43);
/* Delete bit 0 */
foo &= ~(1 << 0);
assert(foo == 42);
/* Toggle bit 5 */
foo ^= (1 << 5);
assert(foo == 10);
foo ^= (1 << 5);
assert(foo == 42);
}