function IntToBinaryStr(TheVal: LongInt): string;
var
  counter: LongInt;
begin
{This part is here because we remove leading zeros.  That
means that a zero value would return an empty string.}
  if TheVal = 0 then begin
    result := '0';
    exit;
  end;

  result := '';
  counter := $80000000;

  {Suppress leading zeros}
  while  ((counter and TheVal) = 0) do begin
    counter := counter shr 1;
    if (counter = 0) then break; {We found our first "1".}
  end;

  while counter > 0 do begin
    if (counter and TheVal) = 0 then result := result + '0'
    else  result := result + '1';
    counter := counter shr 1;
  end;
end;