CompareByte function
Compare 2 memory buffers byte per byte.
Declaration
function CompareByte(const buf1; const buf2; len: SizeInt): SizeIntDescription
CompareByte compares two memory regions
buf1,
buf2 on a
byte-per-byte basis for a total of
len bytes.
The function returns one of the following values:
- less than 0
- if
buf1andbuf2contain different bytes in the firstlenbytes, and the first such byte is smaller inbuf1than the byte at the same position inbuf2. - 0
- if the first
lenbytes inbuf1andbuf2are equal. - greater than 0
- if
buf1andbuf2contain different bytes in the firstlenbytes, and the first such byte is larger inbuf1than the byte at the same position inbuf2.
Errors
None.
See also
Example: ex99
Program Example99;
{ Program to demonstrate the CompareByte function. }
Const
ArraySize = 100;
HalfArraySize = ArraySize Div 2;
Var
Buf1,Buf2 : Array[1..ArraySize] of byte;
I : longint;
Procedure CheckPos(Len : Longint);
Begin
Write('First ',Len,' positions are ');
if CompareByte(Buf1,Buf2,Len)<>0 then
Write('NOT ');
Writeln('equal');
end;
begin
For I:=1 to ArraySize do
begin
Buf1[i]:=I;
If I<=HalfArraySize Then
Buf2[I]:=I
else
Buf2[i]:=HalfArraySize-I;
end;
CheckPos(HalfArraySize div 2);
CheckPos(HalfArraySize);
CheckPos(HalfArraySize+1);
CheckPos(HalfArraySize + HalfArraySize Div 2);
end.An experiment, built from development snapshots. Not the official Free Pascal or Lazarus documentation.
