Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //A Simple Decimal-to-Binary program.
- #include <iostream>
- #include <bitset>
- using namespace std;
- int main()
- {
- int decimal_number;
- const int number_of_bits=8; //e.g: 8 bits, also should be const.
- string binary_number;
- cout<<"Dec: ";
- cin>>decimal_number;
- binary_number=bitset<number_of_bits>(decimal_number).to_string();
- cout<<"Bin: "<<binary_number;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement