Thread: reading hex file and add them

  1. #1
    Registered User
    Join Date
    Dec 2011
    Posts
    6

    reading hex file and add them

    Hi guys, it will be helpful if someone can check my code and try to correct me....im trying to read a .txt file where inside this file all the hex values
    18 77 FF 12 F8 6B 18 00 FF 03 F8 68 18 00 FE FF B8 77 FF 12 F8 6B 18 00 FF 03 F8 68 18 00 FE FF B8 F7 77 00 00 F8 10 11 00 10 12 72 85 02 12 48 00 F0 01 00 F8 3B 80 81 76 B6 03 10
    i want to read each line at a time and add all the values on that line to get the total value. each line has 32 hex value.

    here is my program:

    Code:
    char filename[] = "C:\\MYFlashValues.txt";
           ifstream inputfile;
           int MYArray[32];
    
           // opening input file for reading
           inputfile.open(filename, ios::in);
           // test if fail to open the file, do…
           // error handling for file opening
      
           if(inputfile.fail())
    
           {
             Message( "file opend properly")
             exit(1);
    
           }  // just exit
    
    
    else
    
           {
           int chksum = 0;
           int Valuecount=0;
           char addrs=0;
           char RecordType=0;
           int temp=0;
           char value;
           short Number;
           short Two;
           int endchksum=0;
           int ArrayCnt=0;
    
    
           // read data from input stream...
    
            while(!inputfile.eof())
            {
                  getline(inputfile, Value);
                  temp= ArrayCnt % 32;
                  if((temp==0)&&(ArrayCnt!=0))
                   {
                      for(int x=0;x<32;x++)
                      {
                         chksum+=MYArray[x];
                         chksum=chksum*0xFF;
                      }
    how can i add hex values?? also i have space between each hex value how can i ignore space and add all the hex values...pls help
    Last edited by Salem; 12-07-2011 at 10:28 PM. Reason: fix tags

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    also xposted here -> Intel hex format - Dev Shed
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Dec 2011
    Posts
    1
    working code has been posted at dev-shed for column- and row-checksums.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 07-17-2011, 03:51 AM
  2. File I/O..Reading a file and printing contents
    By eeengenious in forum C Programming
    Replies: 2
    Last Post: 03-14-2011, 05:58 PM
  3. Replies: 13
    Last Post: 05-31-2009, 11:30 AM
  4. Reading in a binary file from offset into another file
    By cloudy in forum C++ Programming
    Replies: 5
    Last Post: 05-24-2006, 03:01 AM
  5. Reading flat file and generating tagged file
    By AngKar in forum C# Programming
    Replies: 4
    Last Post: 03-24-2006, 08:29 AM