Einzelnen Beitrag anzeigen

Eichhoernchen

Registriert seit: 22. Apr 2004
Ort: Hagen
322 Beiträge
 
Turbo Delphi für Win32
 
#7

Re: Chiffre BinärtoText TexttoBinär

  Alt 15. Okt 2005, 18:43
mann muss einen Zeileumbruch abfangen der ja #10#13 entspricht!

ich hab mich auchmal versucht sowas zu Programmieren:

Delphi-Quellcode:
function TBin.texttobin(s : string) : string;
var i, j : integer;
    c : char;
Begin
 result := '';
 for i := 1 to length(s) do
  Begin
   c := s[i];
   if s[i] = #10
     then Begin
           result := result + #10;
           continue;
          end
     else if s[i] = #13
            then Begin
                  result := result + #13;
                  continue;
                 end;
   for j := 7 downto 0 do
     if byte(c) and (1 shl j) <> 0
       then result := result + '1'
       else result := result + '0';
   result := result + ' ';
  end;
end;

function TBin.bintotext(s : string) : string;
var i, preres, j : integer;
    b : string;
Begin
 result := '';
 i := 1;
 while i < length(s) do
  Begin
    preres := 0;
    b := '';
    if s[i] = ' '
      then Begin
            inc(i);
            continue;
           end
      else if (s[i] = #10)
              then Begin
                    inc(i,2);
                    result := result + #10;
                    continue;
                   end
              else if (s[i] = #13)
                      then Begin
                            inc(i,2);
                            result := result + #13;
                            continue;
                           end;
    for j := i to i+7 do
     b := b + s[j];
    for j := 8 downto 1 do
     preres := preres + (StrToInt(b[j]) shl (8-j));
   result := result + chr(preres);
   inc(i, 8);
  end;
end;
Jan
  Mit Zitat antworten Zitat