AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

boolarrtostr ???

Ein Thema von braingrenade · begonnen am 9. Okt 2003 · letzter Beitrag vom 10. Okt 2003
Antwort Antwort
Benutzerbild von braingrenade
braingrenade

Registriert seit: 30. Okt 2002
Ort: Neufra
274 Beiträge
 
Delphi 6 Personal
 
#1

boolarrtostr ???

  Alt 9. Okt 2003, 14:47
Moin leute !!

Ich möchte gerne ein boolarr
type Tboolarr = array of Boolean ; in einen string umwandeln also zb. 00101010100111111000001010100101 in 'xyz' .
ich hab mir auch schon ne function geschrieben , welche aber als result immer '' ausgiebt .
Delphi-Quellcode:
function bintobyte(const AsValue : string) : byte;
//Danke an Daniel B für diese Funktion !!!!
const
  _aBinDigits = ['0','1'];

var
  iPowerOfTwo : integer;
  i : integer;

begin
  Result := 0;
  iPowerOfTwo := 1;
  if (length(AsValue) < 1) or (length(AsValue) > 8) then
  begin
    raise Exception.Create('Die Zahl muss zwischen 1 und 8 Stellen haben.');
  end;
  for i := length(AsValue) downto 1 do
  begin
    if not (AsValue[i] in _aBinDigits) then
    begin
      raise Exception.Create('Es dürfen nur die Ziffern 0 und 1 vorkommen.');
    end;
    if AsValue[i] = '1then
    begin
      Result := Result or iPowerOfTwo;
    end;
    iPowerOfTwo := iPowerOfTwo shl 1;
  end;
end;

//in diser Funktion liegt der Fehler
function Tbitcrypt.boolarrtostr(ba : Tboolarr): string;
var i,i2 : integer;
    buf,b : string;
begin
result := '';
for i := 0 to high(ba) do
begin
 if ba[i] = true then buf := buf +'1'
 else buf := buf + '0';
end;

i:=1;
i2:=0;
repeat
 if i2 = 8 then
  begin
   i2 :=0;
   result := result+ char(bintobyte(b));
   b := '';
  end;
 b := b+buf[i];
 i2 := i2 +1;
 i:=i+1;
until i = length(buf)+2;
end;
Weiß jemand woran das liegen könnte ?
Let the sun beat down upon my face
Stars fill my dream
I am a traveller of both time and space
To be where I have been ________________ Such A Surge
  Mit Zitat antworten Zitat
Honie

Registriert seit: 27. Sep 2003
Ort: Bielefeld
39 Beiträge
 
Delphi 7 Enterprise
 
#2

Re: boolarrtostr ???

  Alt 9. Okt 2003, 15:06
soweit wie ich es sehe, solltest Du auf jedenfall buf initilisieren.

Also:

buf := ''

am Anfang.

Ansonsten kann ich durch den unstrukturierten Code nicht
so schnell durchblicken.
  Mit Zitat antworten Zitat
Benutzerbild von braingrenade
braingrenade

Registriert seit: 30. Okt 2002
Ort: Neufra
274 Beiträge
 
Delphi 6 Personal
 
#3

Re: boolarrtostr ???

  Alt 9. Okt 2003, 15:25
Mion honie , leider funzt immer noch nich
Let the sun beat down upon my face
Stars fill my dream
I am a traveller of both time and space
To be where I have been ________________ Such A Surge
  Mit Zitat antworten Zitat
Benutzerbild von sakura
sakura

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

Re: boolarrtostr ???

  Alt 9. Okt 2003, 15:36
Du musst sowohl Buf auf '' initialisieren (wichtig spätestens ab dem 2. Aufruf) und

Result := Buf;

......
Daniel W.
Ich bin nicht zurück, ich tue nur so
  Mit Zitat antworten Zitat
Benutzerbild von braingrenade
braingrenade

Registriert seit: 30. Okt 2002
Ort: Neufra
274 Beiträge
 
Delphi 6 Personal
 
#5

Re: boolarrtostr ???

  Alt 9. Okt 2003, 15:47
Ich glaub ich steh grad auf dem Schlauch !!
Meint ihr das so :
Delphi-Quellcode:
function Tbitcrypt.boolarrtostr(ba : Tboolarr): string;
var i,i2 : integer;
    buf,b : string;
begin
buf:=''; // das is neu
for i := 0 to high(ba) do
begin
 if ba[i] = true then buf := buf +'1'
 else buf := buf + '0';
end;
result := '';
b:=''; // und das is neu
i:=1;
i2:=0;
repeat
 if i2 = 8 then
  begin
   i2 :=0;
   result := result+ char(bintobyte(b));
   b := '';
  end;
 b := b+buf[i];
 i2 := i2 +1;
 i:=i+1;
until i = length(buf)+2;
end;
?
Let the sun beat down upon my face
Stars fill my dream
I am a traveller of both time and space
To be where I have been ________________ Such A Surge
  Mit Zitat antworten Zitat
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
Benutzerbild von braingrenade
braingrenade

Registriert seit: 30. Okt 2002
Ort: Neufra
274 Beiträge
 
Delphi 6 Personal
 
#7

Re: boolarrtostr ???

  Alt 9. Okt 2003, 16:12
Wow !

Danke für die schnelle Hilfe!
Let the sun beat down upon my face
Stars fill my dream
I am a traveller of both time and space
To be where I have been ________________ Such A Surge
  Mit Zitat antworten Zitat
Benutzerbild von sakura
sakura

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

Re: boolarrtostr ???

  Alt 10. Okt 2003, 12:10
Ich habe obige Version noch um eine Sicherheitsabfrage und eine kleine Feinheit erweitert, damit es nicht zu Fehlern kommt

......
Daniel W.
Ich bin nicht zurück, ich tue nur so
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 20:08 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz