#include <iostream> #include <sstream> #include <bitset> std::string getBinaryFormat(char c) { return std::bitset<8>(c).to_string(); } std::string get(char m_v) { std::ostringstream buff; for (int i = 7; i >= 0; --i) buff << ((m_v & (1 << i)) ? "1" : "0"); return buff.str(); } int main() { std::cout << getBinaryFormat('a') << std::endl << get('a') << std::endl; return 0; }
Améliorer votre expérience CodeS-SourceS avec ce plugin:
ttp://codes-sources.commentcamarche.net/forum/affich-10000111-plugin-better-cs-2#cptpingu-signature