Split an integer into binary equivalent integers


SUBMITTED BY: Guest

DATE: June 4, 2013, 7:09 p.m.

FORMAT: C++

SIZE: 579 Bytes

HITS: 1235

  1. #include <string>
  2. #include <sstream>
  3. using namespace::std;
  4. int main()
  5. {
  6. unsigned long long start = 0xABCDEF1234567890;
  7. stringstream ss;
  8. ss << hex << start;
  9. string end = ss.str();
  10. string firsthalf = end.substr(0,8);
  11. string endhalf = end.substr(8,8);
  12. ss.str(string());
  13. ss << hex << firsthalf;
  14. unsigned long firstint;
  15. ss >> firstint;
  16. stringstream ss2;
  17. ss2 << hex << endhalf;
  18. unsigned long secint;
  19. ss2 >> secint;
  20. printf("\n%s=>%lu\n\n%s=>%lu",firsthalf,firstint,endhalf,secint);
  21. return 0;
  22. }

comments powered by Disqus