Solved

How do you Save Binary file with some requirements?

Posted on 2003-10-23
6
350 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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. …
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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…

896 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now