Changeset 31 for BitStream/test.lpr
- Timestamp:
- Jun 24, 2010, 4:18:03 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
BitStream/test.lpr
r30 r31 16 16 17 17 TTest = class(TCustomApplication) 18 private 19 procedure PrintBitStream(Stream:TBitStream); 18 20 protected 19 21 procedure DoRun; override; … … 39 41 Buffer[2] := $56; 40 42 Buffer[3] := $78; 43 WriteLn('Source data:'); 41 44 PrintData(Buffer); 42 45 43 BitStream.Write(Buffer[0], 27); 46 BitStream.Write(Buffer[0], 28); 47 WriteLn('Write data to stream:'); 48 PrintBitStream(BitStream); 44 49 // Write second bit array after first which lead to store data as shifted 45 BitStream.Write(Buffer[0], 27); 46 47 BitStream.Stream.Position := 0; 48 PrintStream(BitStream.Stream); 50 BitStream.Write(Buffer[0], 28); 51 WriteLn('Append shifted data to stream:'); 52 PrintBitStream(BitStream); 49 53 50 54 // Read test of sub bit array 51 BitStream.Position := 5; 52 BitStream.Read(Buffer[0], 18); 55 BitStream.Position := 1; 56 BitStream.Read(Buffer[0], 32); 57 WriteLn('Read bit data part:'); 53 58 PrintData(Buffer); 54 59 55 60 // Test stream copy 56 BitStream.Position := 2; 57 BitStream2.CopyFrom(BitStream, BitStream.Size); 58 PrintStream(BitStream2.Stream); 61 WriteLn('Copy bit block to another stream:'); 62 for I := 0 to BitStream.Size do begin 63 BitStream.Position := I; 64 BitStream2.Size := 0; 65 BitStream2.CopyFrom(BitStream, BitStream.Size); 66 PrintBitStream(BitStream2); 67 end; 68 for I := 0 to BitStream.Size do begin 69 BitStream.Position := 0; 70 BitStream2.Size := 0; 71 BitStream2.Position := I; 72 BitStream2.CopyFrom(BitStream, BitStream.Size); 73 PrintBitStream(BitStream2); 74 end; 59 75 60 76 BitStream.Destroy; … … 68 84 var 69 85 I: Integer; 86 B: Integer; 87 OneByte: Byte; 70 88 begin 71 for I := 0 to High(Data) do 72 Write(IntToHex(Data[I], 2) + ' '); 89 for I := 0 to High(Data) do begin 90 OneByte := Data[I]; 91 for B := 0 to 7 do 92 Write(IntToStr((OneByte shr B) and 1)); 93 end; 73 94 WriteLn; 74 95 end; … … 77 98 var 78 99 I: Integer; 100 B: Integer; 101 Data: Byte; 102 begin 103 Stream.Position := 0; 104 for I := 0 to Stream.Size - 1 do begin 105 Data := Stream.ReadByte; 106 for B := 0 to 7 do 107 Write(IntToStr((Data shr B) and 1)); 108 end; 109 WriteLn; 110 end; 111 112 procedure TTest.PrintBitStream(Stream: TBitStream); 113 var 114 I: Integer; 79 115 begin 80 116 Stream.Position := 0; 81 117 for I := 0 to Stream.Size - 1 do 82 Write(IntTo Hex(Stream.ReadByte, 2) + ' ');118 Write(IntToStr(Integer(Stream.ReadBit))); 83 119 WriteLn; 84 120 end;
Note:
See TracChangeset
for help on using the changeset viewer.