谢谢beta,有空我一定试试你的程序,我已经搞掂了!
var
InFile,OutFile:TextFile;
Str,StrToWrt:String;
I,J,N,Count,Rec,Sum:Integer;
B:Byte;
C:Char;
begin
SetLength(Str,1024);
AssignFile(InFile,'D:/DELPHI/DataForCh.txt');
AssignFile(OutFile,'D:/DELPHI/ResultData.txt');
try
ReSet(InFile);
ReWrite(OutFile);
//
While not Eof(InFile) do
begin
Readln(InFile,Str);
N:=Length(Str);
Count:=Trunc(N div $8);
SetLength(StrToWrt,Count+1);
Rec:=N mod $8;
//补零
if Rec<>0 then
begin
Rec:=$8-Rec;
for I:=1 to Rec do
Str:=Str+'0';
Count:=Count+1;
end;
//每次取8个字符
for I:=0 to Count-1 do
begin
Sum:=0;
for J:=1 to 8 do
//完成转换和存储
begin
Sum:=Sum+Trunc(IntPower(2,J-1))*StrToInt(Str[I*8+J]);
end;
B:=Byte(Sum);
C:=Chr(B);
StrToWrt[I+1]:=C;
end;
Writeln(OutFile,StrToWrt);
end;
finally
CloseFile(InFile);
CloseFile(OutFile);
end;
Close;
end;