Algorithm Math Delphi

function DecToBin(Z:Integer):String;
var
BinString: String;
v,Index: Integer;
begin
Index := 1;
v:=0;
BinString := '';
Repeat
if index>v then v:=v+4;
BinString := IntToStr(Z mod 2) + BinString;
if (Index mod 4 = 0) then BinString := ' ' + BinString;
Z := Z div 2;
Inc (Index);
Until (Z=0)and (Index > v);
DecToBin := TrimLeft(BinString);
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
Edit1.Text:=Dectobin(strtoint(Edit1.text));
end;