[Overview][Constants][Types][Classes][Procedures and functions][Variables][Index] Reference for unit 'System' (#rtl)

CompareByte

Compare 2 memory buffers byte per byte

Declaration

Source position: systemh.inc line 795

function CompareByte(

  const buf1;

  const buf2;

  len: SizeInt

):SizeInt;

Description

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 buf1 and buf2 contain different bytes in the first len bytes, and the first such byte is smaller in buf1 than the byte at the same position in buf2.
0
if the first len bytes in buf1 and buf2 are equal.
greater than 0
if buf1 and buf2 contain different bytes in the first len bytes, and the first such byte is larger in buf1 than the byte at the same position in buf2.

Errors

None.

See also

CompareChar

  

compare 2 memory buffers character per character

CompareChar0

  

Compare two buffers character by character till a null-character is reached.

CompareWord

  

Compare 2 memory buffers word per word

CompareDWord

  

Compare 2 memory buffers DWord per DWord

Example

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.

Documentation generated on: May 14 2021