Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bitset>
- #include <iostream>
- #include <string>
- #include <sstream>
- using namespace std;
- int main ()
- {
- const char* const str = "0x31c3";
- std::istringstream iss(str);
- int i;
- iss >> std::hex >> i;
- if(!iss && !iss.eof()) throw "dammit!";
- std::cout << '"' << str << "\": " << i << "(0x" << std::hex << i << ")\n";
- bitset<16> bs=i;
- cout << "Binary : " << bs.to_string<char,char_traits<char>,allocator<char> >() << endl;
- // to_string returns an std::string with the binary digits ( 000...0111 )
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement