Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
C++ Program to Print Binary
//Example program to print binary representation #include <iostream> using namespace std; // function to print thing out as binary void printBinary(unsigned int myNumber) { int numberOfBits = sizeof(unsigned int)*8; for (int i=numberOfBits-1; i>=0; i--) { bool isBitSet = (myNumber & (1<<i)); if (isBitSet) { cout << "1"; } else { cout << "0"; } } } int main(void) { unsigned int number; cout << "Input an integer number: "; // read in the integer cin >> number; // print out as decimal cout << endl << "Your input in decimal: " << number << endl; // print out as decimal cout << "Your input as binary: "; printBinary(number); // all done cout << endl << "Wasn't that fun?" << endl; return 0; }
run
|
edit
|
history
|
help
0
vector flavors....
Find in vector vs unordered_map
Tree Example
Throttle Example (Send two requests every two seconds)
program_4
List comprehension in C++ using functional patterns
Reverse polish notation
template specialization inheritance problem
Graphs Iteration2 Directed Graphs
Test size_t