Advertisement
skb50bd

Decimal to Binary

Mar 20th, 2015
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.34 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5.     int dec, rem, bin = 0;
  6.     cout << "Enter the Decimal Number: ";
  7.     cin >> dec;
  8.  
  9.     for(int i = 1; dec; i *= 10) {
  10.         rem = dec % 2;
  11.         dec /= 2;
  12.         bin += rem * i;
  13.     }
  14.     cout << "The Corresponding Binary Value is: " << bin << endl;
  15.  
  16.     return 0;
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement