Advertisement
Guest User

halluc1nati0n

a guest
Nov 29th, 2009
935
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. #include <bitset>
  2. #include <iostream>
  3. #include <string>
  4. #include <sstream>
  5. using namespace std;
  6.  
  7. int main ()
  8. {
  9.  
  10.     const char* const str = "0x31c3";
  11.     std::istringstream iss(str);
  12.     int i;
  13.     iss >> std::hex >> i;
  14.     if(!iss && !iss.eof()) throw "dammit!";
  15.     std::cout << '"' << str << "\": " << i << "(0x" << std::hex << i << ")\n";
  16.     bitset<16> bs=i;
  17.     cout << "Binary : " << bs.to_string<char,char_traits<char>,allocator<char> >() << endl;
  18.                  // to_string returns an std::string with the binary digits ( 000...0111 )
  19.     return 0;
  20.    
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement