fork download
  1. #include <iostream>
  2.  
  3. typedef unsigned char byte;
  4.  
  5. #define SYSTEMBYTEORDER 0x3210
  6. #define SOMESHITTYBYTEORDER 0x0123
  7. #define YETANOTHERBYTEORDER 0x1032
  8.  
  9. template < int b0, int b1, int b2, int b3, int b4 = b0 + 4, int b5 = b1 + 4, int b6 = b2 + 4, int b7 = b3 + 4 >
  10. struct ByteOrder {
  11.  
  12. static int GetInt ( int arf ) {
  13. byte* b = (byte*)&arf;
  14. return b[b0] | ( b[b1] << 8 ) | ( b[b2] << 16 ) | ( b[b3] << 24 );
  15. }
  16.  
  17. };
  18.  
  19. template <int order>
  20. struct HexByteOrder :
  21. public ByteOrder< (order & 0xF), ((order & 0xF0) >> 4), ((order & 0xF00) >> 8), ((order & 0xF000) >> 12) >
  22. {};
  23.  
  24. int main (int argc, char* argv[]) {
  25.  
  26. std::cout << std::hex;
  27. std::cout << "Argc before: " << argc << std::endl;
  28. std::cout << "Argc with SOMESHITTYBYTEORDER: " << HexByteOrder<SOMESHITTYBYTEORDER>::GetInt( argc ) << std::endl;
  29. std::cout << "Argc with YETANOTHERBYTEORDER: " << HexByteOrder<YETANOTHERBYTEORDER>::GetInt( argc ) << std::endl;
  30. std::cout << "Argc with SYSTEMBYTEORDER: " << HexByteOrder<SYSTEMBYTEORDER>::GetInt( argc ) << std::endl;
  31.  
  32. }
Success #stdin #stdout 0s 2884KB
stdin
Bua ha ha ha~
stdout
Argc before: 1
Argc with SOMESHITTYBYTEORDER: 1000000
Argc with YETANOTHERBYTEORDER: 10000
Argc with SYSTEMBYTEORDER: 1