My code is to read a file of hex numbers then to convert them to binary .
First problem :
that it reads the lines and convert them to binary but the last digit of the first line is not converted !!
Ex:
hex no :
023F8 // 8 won't be converted ??
11245
0223A
bin no:
0000001000111111
00010001001001000101
00000010001000111010
Second problem :
The file that i read from it the hex numbers contain some comments that we must read them and print them out in the screen, you can notice that i interested in
keeping those comments not converted, but it doesn't work ??
The File Content :
!!
!!
!!
!! This is a comment line
!! START = 00100
!! LAST = 00118
!! CODE
!! LSB_...._MSB
!! instructions
032018
6B2015
0B2012
6F200F
77200C
072009
1B2006
2B2003
0F2003
000001
instead of assuming 6 characters in the string, use the actual length
for (int i=0; i<x.size(); i++)
While we're talking about this code, a couple of other thoughts.
Instead of this:
61 62 63
while(!myfile.eof())
{
getline (myfile,l1);
do this, it is less error prone:
61 62
while(getline (myfile,l1))
{
As for the comment lines in the file, I suggest you identify those by checking for "!!" as the first two characters ( be careful if the line has less than two characters).