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] = '
1'
then
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 ?