Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // decimal to binary
- #include <iostream>
- #include <string>
- using namespace std;
- int main() {
- int num;
- cout << "Decimal: ";
- cin >> num;
- string binNum;
- int x = num;
- while (x > 0) {
- binNum.insert(0, to_string(x % 2));
- x /= 2;
- }
- cout << "Binary representation of " << num << " is " << binNum << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement