Bitwise Operators in C

Level 258 keystrokes

Applies bitwise AND, OR and XOR to 5 (binary 101) and 3 (binary 011) and prints the results "1 7 6".

C code

// In binary, a = 5 is 101 and b = 3 is 011
1int a = 5, b = 3;
// & keeps bits set in both (001 = 1), | in either (111 = 7), ^ in exactly one (110 = 6)
2printf("%d %d %d", a & b, a | b, a ^ b);

Output

1 7 6
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this C code and how often they appear.

  • ,× 4
  • %× 3
  • ;× 2
  • "× 2
  • =× 2
  • (× 1
  • )× 1
  • &× 1
  • ^× 1
  • |× 1

More C examples at level 2

← C typing practice