Advertisement
Guest User

Untitled

a guest
May 24th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.38 KB | None | 0 0
  1. //A Simple Decimal-to-Binary program.
  2. #include <iostream>
  3. #include <bitset>
  4. using namespace std;
  5. int main()
  6. {
  7.     int decimal_number;
  8.     const int number_of_bits=8; //e.g: 8 bits, also should be const.
  9.     string binary_number;
  10.     cout<<"Dec: ";
  11.     cin>>decimal_number;
  12.     binary_number=bitset<number_of_bits>(decimal_number).to_string();
  13.     cout<<"Bin: "<<binary_number;
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement