Sorry, auch gerade gemerkt.
Hier die Komplettlösung - hin und zurück:
Delphi-Quellcode:
function IntToStr(IntNumber: Integer): string;
begin
Str(IntNumber, result);
end;
function StrToInt(s: String): Integer;
var
code: Integer;
begin
val(s, result, code);
end;
function IntToBin(IntNumber: Integer): string;
function OtherWayRound(s: string): string;
var
Loop: Integer;
begin
for Loop := length(s) downto 1 do
begin
result := result + s[Loop];
end;
end;
var
res: Integer;
begin
res := IntNumber;
while res <> 0 do
begin
result := result + IntToStr(res mod 2);
res := res div 2;
end;
result := OtherWayRound(result);
end;
function BinToInt(s: string): Integer;
var
Loop: Integer;
Multiplier: Integer;
begin
result := 0;
Multiplier := 1;
for Loop := 1 to length(s) do
begin
result := result + StrToInt(s[Loop]) * Multiplier;
Multiplier := Multiplier * 2;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
const
IntNumber = 17;
BinNumber = '10001';
begin
ShowMessage(IntToBin(IntNumber));
ShowMessage(IntToStr(BinToInt(BinNumber)));
end;
Probier deinen Code doch aus.