Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Assuming your file is a long bit stream containing 9-bit blocks and you want to output the same stream but with 8-bit blocks (i.e. dropping every 9th bit).</p> <p>You could read 9 bytes at a time (72 bits = eight 9-bit blocks) and then use bit shifting to put these into eight 8-bit blocks.</p> <p>You would need some special processing to handle a file that isn't a multiple of 9 bytes, so this is just a rough guide.</p> <pre><code>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 &lt; 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; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload