Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void BinToAscFile(const std::string &binfile,const std::string &txtfile)
- {
- {
- std::ifstream infile( binfile, std::ios::binary );
- std::ofstream outfile(txtfile);
- unsigned char v ;
- char temp[4];
- ZeroMemory(temp,4);
- while( infile.read( reinterpret_cast<char*>(&v), sizeof(v) ) )
- {
- sprintf(temp,"%02x",v);
- outfile << temp << ' ' ;
- }
- outfile << '\n' ;
- }
- }
- void AscToBinFile(const std::string &txtfile,const std::string &binfile)
- {
- {
- std::vector<unsigned char> seq ;
- {
- std::ifstream file(txtfile) ;
- char temp[4];
- while( !file.eof())
- {
- file >> temp;
- unsigned char c = strtol(temp,NULL,16);
- seq.push_back((unsigned char)c) ;
- }
- }
- {
- std::ofstream file( binfile, std::ios::binary ) ;
- for( unsigned char v : seq ) file.write( reinterpret_cast<const char*>(&v), sizeof(v) ) ;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement