Solved

How do you Save Binary file with some requirements?

Posted on 2003-10-23
6
349 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
Comment Utility
Do you need help in converting the Hex string back to binary bytes?
0
 
LVL 30

Accepted Solution

by:
Axter earned 500 total points
Comment Utility
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
Comment Utility
Hello,

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

Thanks
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 7

Expert Comment

by:burcarpat
Comment Utility
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
Comment Utility
Hello,

Just trying to do some work:)

Any helps?

Thanks
0
 
LVL 22

Expert Comment

by:ambience
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
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 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 how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

762 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