CFile file(m_path,CFile::modeRead);
char a[8];//ZeroMemory(a,0);
//file.Read(a,8);
char b[65536]={0};file.Read(b,65535);
int ibina[8];
//char cRead[8];
char cChar;
CString str;int cnt=0;
for(;b[cnt]!='\0';cnt+=8)
{file.Read(a,8);
//file.Read(cRead,8);
for(int i=0;i<8;i++)
{
ibina[i]=a[i]-'0';}
int itemp=1;
cChar=0;
for(int j=7;j>=0;j--)
{
cChar+=ibina[j]*itemp;
itemp*=2;
}
//cnt+=1;
str.Format("%c",cChar);
m_txt+=str;
}
file.Close();
UpdateData(false);
}//if
为什么输出地都是d. 想把输入的2进制文件转成文本。。?
就这一块老出问题,不是输出地文本不完全,就是输出地都是d。
{file.Read(a,8);为什么要这么读取?你一个个字节处理不好吗?
int ibina[8];
//char cRead[8];
char cChar;
CString str;int cnt=0;
for(;b[cnt]!='\0';cnt+=8)
{file.Read(a,8);// 这里再读的时候已经不是你想读取的位置了
//Fill a string array in hex format
BOOL CWindisavrDoc::StringBin()
{
BYTE *pTmp=m_pBuffer;
CString tmp;
CString prompt;
BYTE comment[40];
//
m_HexStrArray.RemoveAll();
//code behind maxSize will not be shown
int maxSize=2*((theApp.m_FlashEnd+1)+(theApp.m_EePromEnd+1));
if (m_nSize < maxSize) maxSize=m_nSize;
//
int FullRows=maxSize/16;
int PartRow=maxSize%16;
//
for(int rr=0;rr < FullRows ; rr++)
{//
tmp.Format("%05X:", 8*rr);//"10000:" 8Words
prompt+=tmp;
for(int col = 0;col < 16; col++)
{
if((*pTmp>' ') && (*pTmp<'z')) comment[col]=*pTmp;
else comment[col]='.';
tmp.Format("%02X ", *pTmp++);
prompt+=tmp;
}
comment[col]=0;
prompt+=" ";
prompt+=comment;
prompt+="\r\n";
m_HexStrArray.Add(prompt);
prompt.Empty();
}
//
if(PartRow!=0)
{
tmp.Format("%05X:", 8*rr);
prompt+=tmp;
for(int col = 0;col < PartRow; col++)
{
if((*pTmp>' ') && (*pTmp<'z')) comment[col]=*pTmp;
else comment[col]='.';
tmp.Format("%02X ", *pTmp++);
prompt+=tmp;
}
comment[col]=0;
while(col<16)
{// more spaces
prompt+=" ";//3
col++;
}
prompt+=" ";
prompt+=comment;
prompt+="\r\n";
m_HexStrArray.Add(prompt);
prompt.Empty();
}
//
return TRUE;
}