You have to save the intermediate results at each iteration of the div/mod - you're just thowing them away (and you also start by overwriting your input with an uninitialised variable).
Here's a GUI approach which needs a memo dropped on a form and an OnCreate form handler.
unit mainDecimalToBinary;
{$mode objfpc}{$H+}
interface
uses
Forms, Controls, StdCtrls, sysutils;
type
TForm1 = class(TForm)
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
end;
// this function writes 8 digits whatever the byte value represented
function ByteValueToBinaryString(bValue: byte;
addB: boolean=True;
prefix: boolean=False): shortstring;
var
Form1: TForm1;
implementation
function ByteValueToBinaryString(bValue: byte; addB: boolean; prefix: boolean
): shortstring;
const NumberOfBinaryDigitsInAByte=8;
var
i : integer;
begin
Result[0]:=Char(NumberOfBinaryDigitsInAByte);
for i:= NumberOfBinaryDigitsInAByte downto 1 do
begin
Result[i]:=Char(Ord('0') + bValue and 1);
bValue:= bValue div 2;
end;
if addB then
if prefix then
Result:='b'+Result
else Result:=Result+'b';
end;
{$R *.lfm}
procedure TForm1.FormCreate(Sender: TObject);
var
i: Integer;
begin
Memo1.Align:=alClient;
Memo1.ScrollBars:=ssAutoVertical;
Memo1.Clear;
for i:= Low(Byte) to High(Byte) do
Memo1.Lines.Add(Format('%s (%d)',[ByteValueToBinaryString(i), i]));
end;
end.