Advertisement
N3rdsWithGame

byteswapper

Nov 5th, 2017
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. #include <fstream>
  2. #include <string>
  3.  
  4. const std::string inFile = "...";
  5. const std::string outFile = "...";
  6.  
  7.  
  8. int main(int argc, char* argv[]) {
  9.  
  10. std::ifstream fin(inFile, std::ios::in | std::ios::binary | std::ios::ate);
  11.  
  12. std::streampos fileSize = fin.tellg();
  13.  
  14. uint8_t* fileData = new uint8_t[fileSize];
  15.  
  16. fin.seekg(0);
  17.  
  18. fin.read(reinterpret_cast<char *>(fileData), fileSize);
  19.  
  20. std::ofstream fout(outFile, std::ios::out | std::ios::binary);
  21.  
  22. int i = 0;
  23. for (i = 0; i < fileSize; i += 2)
  24. fout << fileData[i + 1] << fileData[i];
  25. if (fileSize % 2 == 1)
  26. fout << (uint8_t)0 << fileData[-1 + fileSize];
  27. fout.close();
  28.  
  29. return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement