Solved

How do you Save Binary file with some requirements?

Posted on 2003-10-23
6
351 Views
Last Modified: 2010-05-18
Hello,

I have one more question about SavingbinaryFile.  I have this function, void saveBinaryFile( string text, string filename), where the parameter filename is the name of the input or the output file, as the case may be, and where the parameter text is the hexadecimal text to be written to the file.  I am doing the whole project called Text Editor and SaveBinaryFile is  one of my functions.  Within the TextEditor, the hex bytes can be edited, and upon saving the binary file (void saveBinaryFile(string text, string filename), it should convert the hex bytes back into binary and write the binary file....i am thinking using "Integer.parseInt(hexByte, 16) for the convsion...any help will be appreciated..

Thanks a lot
0
Comment
Question by:daskino12
6 Comments
 
LVL 30

Expert Comment

by:Axter
ID: 9611383
Do you need help in converting the Hex string back to binary bytes?
0
 
LVL 30

Accepted Solution

by:
Axter earned 500 total points
ID: 9611391
Here are a couple of conversion functions.

template< typename T > std::string HexStrToBinaryStr(const T &HexStr, const char MaxWidth = 32)
{
      std::istringstream ist(HexStr);
      int value;
      ist >> std::hex >> value;
      return std::bitset<256>(value).to_string().c_str() + (256-MaxWidth);
}
template< typename T > char HexStrToChar(const T &HexStr)
{
      std::istringstream ist(HexStr);
      int value;
      ist >> std::hex >> value;
      return value;
}
template< typename T > int HexStrToInt(const T &HexStr)
{
      std::istringstream ist(HexStr);
      int value;
      ist >> std::hex >> value;
      return value;
}
0
 

Author Comment

by:daskino12
ID: 9611462
Hello,

Acutally, i need help for writing this subroutine, void saveBinaryFile(string text, string filename).

Thanks
0
ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 
LVL 7

Expert Comment

by:burcarpat
ID: 9611496
this looks awfully like the hw/project we had many years ago in a c++ class.  are you sure this is not a hw?

-- ba
0
 

Author Comment

by:daskino12
ID: 9611648
Hello,

Just trying to do some work:)

Any helps?

Thanks
0
 
LVL 22

Expert Comment

by:ambience
ID: 9612020
do a simple cout <<  text and post the results here, this will help understand what kind of coversion you require.

Creating a binary file and writing data to it is easily accomplished by using ofstream. Can you post what you have done so far (within saveAsBiinary)  ?
0

Featured Post

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question