Right Shift in C++

Level 125 keystrokes

Shifts 8 right by 2 bits and prints the result, 2.

C++ code

// >> shifts the bits to the right; for non-negative values this divides by a power of 2
// 8 is 1000 in binary; shifting right by 2 gives 10, which is 2 (8 / 4)
1cout << (8 >> 2) << endl;

Output

2
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
  • >× 2
  • ;× 1
  • (× 1
  • )× 1

More C++ examples at level 1

← C++ typing practice