Advertisement
Madmouse

Functional C++11 tools for j00

Feb 5th, 2015
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.98 KB | None | 0 0
  1. // ----------------------------------------------------------------------------
  2. // THE BEER-WARE LICENSE (Revision 43):
  3. // <aaronryool@gmail.com> wrote this file. As long as you retain this notice you
  4. // can do whatever you want with this stuff. If we meet some day, and you think
  5. // this stuff is worth it, you can buy me a beer in return
  6. // ----------------------------------------------------------------------------
  7.  
  8. #define SIZE_BYTE 8
  9. #define SIZE_WORD 16
  10. #define SIZE_DOUBLEWORD 32
  11. #define SIZE_QUADWORD 64
  12. #define SIZE_DOUBLEQUADWORD 128
  13.  
  14. int Madnsize(long unsigned x)
  15. {
  16.     return  x&0xFFFFFFFF00000000 ? SIZE_QUADWORD :
  17.             x&0xFFFF0000 ? SIZE_DOUBLEWORD :
  18.                 x&0xFF00 ? SIZE_WORD:
  19.                     SIZE_BYTE;
  20. }
  21.  
  22. int Madstrtoul(std::string s)   // better stoul
  23. {
  24.     return (s.find("h") != std::string::npos || s.find("0x") != std::string::npos ||
  25.         s.find("q") != std::string::npos) ? std::stoul(s, nullptr, s.find("q")!=std::string::npos ? 8 : 16) :
  26.                 std::stoul(s, nullptr, 0);
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement