C++ Online Compiler
Example: Bitwise Left Shift Example in C++
C
C++
C#
Java
Python
PHP
main.cpp
STDIN
Run
// Bitwise Left Shift Example #include <iostream> #include <bitset> // For binary representation int main() { int num = 5; // Binary: 00000101 std::cout << "Original number: " << num << " (Binary: " << std::bitset<8>(num) << ")" << std::endl; // Shift left by 1 position (5 * 2^1 = 10) int shiftedLeft1 = num << 1; std::cout << "Shifted left by 1: " << shiftedLeft1 << " (Binary: " << std::bitset<8>(shiftedLeft1) << ")" << std::endl; // Shift left by 3 positions (5 * 2^3 = 40) int shiftedLeft3 = num << 3; std::cout << "Shifted left by 3: " << shiftedLeft3 << " (Binary: " << std::bitset<8>(shiftedLeft3) << ")" << std::endl; return 0; }
Output
Clear
ADVERTISEMENTS