Skip to content

Instantly share code, notes, and snippets.

@nukopy
Created January 4, 2019 14:55
Show Gist options
  • Save nukopy/bdfe25c0397a3438585ff36e1fda351b to your computer and use it in GitHub Desktop.
Save nukopy/bdfe25c0397a3438585ff36e1fda351b to your computer and use it in GitHub Desktop.
decimal to binary string.
#include <iostream>
#include <string>
#include <bitset> // static_cast<std::bitset<8>>
#include <sstream> // std::stringstream
using namespace std;
int main() {
int num = 55;
stringstream ss;
ss << std::bitset<8>(num);
string s = ss.str();
cout << s << "\n";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment