Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
File 使用Delphi从文件中删除奇偶校验位(每九位一次)_File_Delphi_Bit Manipulation_Delphi 6 - Fatal编程技术网

File 使用Delphi从文件中删除奇偶校验位(每九位一次)

File 使用Delphi从文件中删除奇偶校验位(每九位一次),file,delphi,bit-manipulation,delphi-6,File,Delphi,Bit Manipulation,Delphi 6,使用Delphi(6)删除文件中的奇偶校验位是否有一种优雅的方法?在这种情况下,奇偶校验位是每9位一次。假设您的文件是一个包含9位块的长位流,并且您希望输出相同的流,但包含8位块(即每9位删除一次) 您可以一次读取9个字节(72位=8个9位块),然后使用位移位将这些字节放入8个8位块中 您需要一些特殊的处理来处理不是9字节倍数的文件,所以这只是一个粗略的指南 procedure TForm1.Button1Click(Sender: TObject); var FSIn: TFileStre

使用Delphi(6)删除文件中的奇偶校验位是否有一种优雅的方法?在这种情况下,奇偶校验位是每9位一次。

假设您的文件是一个包含9位块的长位流,并且您希望输出相同的流,但包含8位块(即每9位删除一次)

您可以一次读取9个字节(72位=8个9位块),然后使用位移位将这些字节放入8个8位块中

您需要一些特殊的处理来处理不是9字节倍数的文件,所以这只是一个粗略的指南

procedure TForm1.Button1Click(Sender: TObject);
var
  FSIn: TFileStream;
  FSOut: TFileStream;
  InBuffer: array[0..8] of Byte;
  OutBuffer: array[0..7] of Byte;
  X: Integer;
  BytesRead: Integer;
  BytesToWrite: Integer;
begin
  FSIn := TFileStream.Create('Input.dat', fmOpenRead);
  FSOut := TFileStream.Create('Output.dat', fmCreate);
  try
    for X := 1 to FSIn.Size div 9 do
    begin
      FillChar(InBuffer[0], 9, 0);
      BytesRead := FSIn.Read(InBuffer[0], 9);
      OutBuffer[0] := InBuffer[0];
      OutBuffer[1] := (InBuffer[1] and 127) shl 1 + (InBuffer[2] and 128) shr 7;
      OutBuffer[2] := (InBuffer[2] and 63) shl 2 + (InBuffer[3] and 192) shr 6;
      OutBuffer[3] := (InBuffer[3] and 31) shl 3 + (InBuffer[4] and 224) shr 5;
      OutBuffer[4] := (InBuffer[4] and 15) shl 4 + (InBuffer[5] and 240) shr 4;
      OutBuffer[5] := (InBuffer[5] and 7) shl 5 + (InBuffer[6] and 248) shr 3;
      OutBuffer[6] := (InBuffer[6] and 3) shl 6 + (InBuffer[7] and 252) shr 2;
      OutBuffer[7] := (InBuffer[7] and 1) shl 7 + (InBuffer[8] and 254) shr 1;

      if BytesRead < 9 then
      begin
        // To do - handle case where 9 bytes could not be read from input
        BytesToWrite := 8;
      end else
        BytesToWrite := 8;

      FSOut.Write(OutBuffer[0], BytesToWrite);
    end;
  finally
    FSIn.Free;
    FSOut.Free;
  end;
end;
procedure TForm1.按钮1点击(发送方:TObject);
变量
FSIn:TFileStream;
FSOut:TFileStream;
InBuffer:字节数组[0..8];
突发:字节数组[0..7];
X:整数;
字节读取:整数;
BytesToWrite:整数;
开始
FSIn:=TFileStream.Create('Input.dat',fmOpenRead);
FSOut:=TFileStream.Create('Output.dat',fmCreate);
尝试
对于X:=1至FSIn.尺寸div 9 do
开始
FillChar(InBuffer[0],9,0);
BytesRead:=FSIn.Read(InBuffer[0],9);
突发事件[0]:=InBuffer[0];
突出物[1]:=(InBuffer[1]和127)shl 1+(InBuffer[2]和128)shr 7;
突出物[2]:=(InBuffer[2]和63)shl2+(InBuffer[3]和192)shr6;
突出物[3]:=(InBuffer[3]和31)shl3+(InBuffer[4]和224)shr5;
突出物[4]:=(InBuffer[4]和15)shl4+(InBuffer[5]和240)shr4;
突出物[5]:=(InBuffer[5]和7)shl5+(InBuffer[6]和248)shr3;
突出物[6]:=(InBuffer[6]和3)shl6+(InBuffer[7]和252)shr2;
突出物[7]:=(InBuffer[7]和1)shl 7+(InBuffer[8]和254)shr 1;
如果字节数小于9,则
开始
//待办事项-处理无法从输入读取9字节的情况
BytesToWrite:=8;
结束其他
BytesToWrite:=8;
Write(exputffer[0],BytesToWrite);
结束;
最后
免费;
FSOut.Free;
结束;
结束;

假设您的文件是一个包含9位块的长位流,并且您希望输出相同的流,但包含8位块(即每9位删除一次)

您可以一次读取9个字节(72位=8个9位块),然后使用位移位将这些字节放入8个8位块中

您需要一些特殊的处理来处理不是9字节倍数的文件,所以这只是一个粗略的指南

procedure TForm1.Button1Click(Sender: TObject);
var
  FSIn: TFileStream;
  FSOut: TFileStream;
  InBuffer: array[0..8] of Byte;
  OutBuffer: array[0..7] of Byte;
  X: Integer;
  BytesRead: Integer;
  BytesToWrite: Integer;
begin
  FSIn := TFileStream.Create('Input.dat', fmOpenRead);
  FSOut := TFileStream.Create('Output.dat', fmCreate);
  try
    for X := 1 to FSIn.Size div 9 do
    begin
      FillChar(InBuffer[0], 9, 0);
      BytesRead := FSIn.Read(InBuffer[0], 9);
      OutBuffer[0] := InBuffer[0];
      OutBuffer[1] := (InBuffer[1] and 127) shl 1 + (InBuffer[2] and 128) shr 7;
      OutBuffer[2] := (InBuffer[2] and 63) shl 2 + (InBuffer[3] and 192) shr 6;
      OutBuffer[3] := (InBuffer[3] and 31) shl 3 + (InBuffer[4] and 224) shr 5;
      OutBuffer[4] := (InBuffer[4] and 15) shl 4 + (InBuffer[5] and 240) shr 4;
      OutBuffer[5] := (InBuffer[5] and 7) shl 5 + (InBuffer[6] and 248) shr 3;
      OutBuffer[6] := (InBuffer[6] and 3) shl 6 + (InBuffer[7] and 252) shr 2;
      OutBuffer[7] := (InBuffer[7] and 1) shl 7 + (InBuffer[8] and 254) shr 1;

      if BytesRead < 9 then
      begin
        // To do - handle case where 9 bytes could not be read from input
        BytesToWrite := 8;
      end else
        BytesToWrite := 8;

      FSOut.Write(OutBuffer[0], BytesToWrite);
    end;
  finally
    FSIn.Free;
    FSOut.Free;
  end;
end;
procedure TForm1.按钮1点击(发送方:TObject);
变量
FSIn:TFileStream;
FSOut:TFileStream;
InBuffer:字节数组[0..8];
突发:字节数组[0..7];
X:整数;
字节读取:整数;
BytesToWrite:整数;
开始
FSIn:=TFileStream.Create('Input.dat',fmOpenRead);
FSOut:=TFileStream.Create('Output.dat',fmCreate);
尝试
对于X:=1至FSIn.尺寸div 9 do
开始
FillChar(InBuffer[0],9,0);
BytesRead:=FSIn.Read(InBuffer[0],9);
突发事件[0]:=InBuffer[0];
突出物[1]:=(InBuffer[1]和127)shl 1+(InBuffer[2]和128)shr 7;
突出物[2]:=(InBuffer[2]和63)shl2+(InBuffer[3]和192)shr6;
突出物[3]:=(InBuffer[3]和31)shl3+(InBuffer[4]和224)shr5;
突出物[4]:=(InBuffer[4]和15)shl4+(InBuffer[5]和240)shr4;
突出物[5]:=(InBuffer[5]和7)shl5+(InBuffer[6]和248)shr3;
突出物[6]:=(InBuffer[6]和3)shl6+(InBuffer[7]和252)shr2;
突出物[7]:=(InBuffer[7]和1)shl 7+(InBuffer[8]和254)shr 1;
如果字节数小于9,则
开始
//待办事项-处理无法从输入读取9字节的情况
BytesToWrite:=8;
结束其他
BytesToWrite:=8;
Write(exputffer[0],BytesToWrite);
结束;
最后
免费;
FSOut.Free;
结束;
结束;

假设您可以将一对一的内容读入整数


i:=ixor 512

假设你能把一对一的东西读入一个整数


i:=ixor 512

您真的要删除位,还是只清除位?9e的意义是什么?你是说每158位是奇偶校验位吗?这似乎很奇怪。我想他是指每一位。(9e是法语,荷兰语是第9个)。类单元定义了一个TBits类,它使用一些技巧来寻址内存块中的位。这有点复杂,但如果您了解发生了什么,它可能会激励您构建使用类似技巧的代码。您真的要删除该位,还是只清除它?9e的意义是什么?你是说每158位是奇偶校验位吗?这似乎很奇怪。我想他是指每一位。(9e是法语,荷兰语是第9个)。类单元定义了一个TBits类,它使用一些技巧来寻址内存块中的位。这有点复杂,但如果您了解发生了什么,它可能会激励您构建使用类似技巧的代码。+1它可以更高效地完成(指针、asm等),但对于非极端情况,这是非常好的。看起来每次读取前需要清除InBuffer,以处理9个字节无法读取的情况。+1可以更高效地执行(指针、asm等),但这在非极端情况下是很好的。看起来每次读取前需要清除InBuffer,以处理9个字节无法读取的情况。但这并没有消除奇偶校验位。但这并没有消除奇偶校验位。