Click here to Skip to main content
15,881,898 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i need it urgently. I have binary files and i have to open the file, read it and convert its data to the text file. the data i require should be in decimal format.
Posted
Comments
OriginalGriff 30-Mar-15 6:11am    
Couple of things:

1) This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
Use the "Improve question" widget to edit your question and provide better information.

2) It may be urgent to you, but it isn't to us. All that your stressing the urgency does is to make us think you have left it too late, and want us to do it for you. This annoys some people, and can slow a response.

1 solution

It is not difficult. For instance with the 'quick and dirty' approach the content of a binary file (assumed to contain 32 bit integers) is reported in decimal representation on the standard output.
C++
nclude <iostream>
#include <fstream>
#include <stdint.h>
using namespace std;


union MU
{
  char buf[4];
  uint32_t u32;
};

int main( int argc, char * argv[])
{

  MU mu;

  if ( argc < 2) return -1;

  ifstream ifs(argv[1], ios::binary);

  while (ifs.good())
  {
    if ( ifs.read(mu.buf, sizeof(mu)).good())
    {
      cout << mu.u32 << endl;
    }
  }
}


C++

 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900