Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How do you Save Binary file with some requirements?

Posted on 2003-10-23
6
Medium Priority
?
357 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 2000 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

604 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