Thema: Delphi boolarrtostr ???

Einzelnen Beitrag anzeigen

Benutzerbild von sakura
sakura

Registriert seit: 10. Jun 2002
Ort: München
11.412 Beiträge
 
Delphi 11 Alexandria
 
#6

Re: boolarrtostr ???

  Alt 9. Okt 2003, 16:04
Ich habe die Proc einfach mal neu geschrieben, und ich denke mal, die tut jetzt, was Du willst. Die ist aber weder auf Speed noch auf Schönheit optimiert, sollte aber logisch nachzuvollziehen sein

Dieses Array [011110000111100101111010] würde dann 'xyz' ergeben

Delphi-Quellcode:
function Boolarrtostr(BA: Tboolarr): string;
var
  TempByte: Byte;
  ArrayPos, Count8Bits, MaxBits: Integer;
begin
  Result := '';
  if Length(BA) = 0 then
    Exit;
  MaxBits := High(BA);
  TempByte := 0;
  Count8Bits := 0;
  ArrayPos := Low(BA);
  while ArrayPos <= MaxBits do
  begin
    TempByte := TempByte shl 1;
    if BA[ArrayPos] then
      TempByte := TempByte or 1;
    Inc(Count8Bits);
    if Count8Bits = 8 then
    begin
      Result := Result + Chr(TempByte);
      TempByte := 0;
      Count8Bits := 0;
    end;
    Inc(ArrayPos);
  end;
  if Count8Bits > 0 then
    Result := Result + Chr(TempByte);
end;
......
Daniel W.
Ich bin nicht zurück, ich tue nur so
  Mit Zitat antworten Zitat