C++ Online Compiler
Example: C++ program to convert decimal to binary using bitwise operator
C
C++
C#
Java
Python
PHP
main.cpp
STDIN
Run
// C++ program to convert decimal to binary using bitwise operator #include <iostream> using namespace std; // The main function of the program int main() { // Step-1 Declare variables int num; // Step-2 Input decimal number cout << "Enter a decimal number: "; cin >> num; // Step-3 Display binary using bitwise operator cout << "Binary representation: "; for (int i = 31; i >= 0; i--) { int bit = (num >> i) & 1; cout << bit; } cout << endl; return 0; }
Output
Clear
ADVERTISEMENTS