function mod_num(n1,n2:integer):integer;//取余数
begin
result:=n1-n1 div n2*n2
end;
function reverse(s:String):String;//取反串
Var
i,num:Integer;
st:String;
begin
num:=Length(s);
st:='';
For i:=numdo
wnTo 1do
begin
st:=st+s;
end;
Result:=st;
end;
Function DecTobin(Value :Integer) : string;//十进制转化二进制
Var
ST:String;
N:Integer;
begin
ST:='';
n:=value;
While n>=2do
begin
st:=st+IntToStr(mod_num(n,2));
n:=n div 2;
end;
st:=st+IntToStr;
Result:= Formatfloat('00000000',StrToFloat(reverse(st)));
end;
function To2Bin(iIn:integer):string;
var
i:integer;
sTmp:string;
begin
I:=iIn;
sTmp:='';
while i>=2do
begin
if (i mod 2)=1 then
begin
sTmp:='1'+stmp;
i:=i div 2;
end
else
begin
stmp:='0'+stmp;
i:=i div 2;
end;
end;
stmp:=chr(ord('0')+i) + stmp;
while length(stmp)<9do
stmp:='0'+stmp;
Result := stmp;
end;
// 原来可以这样简单的
function byte_bin_st(abyte : byte) : string;
var bst : string;
i : integer;
b : byte;
begin
bst := '00000000';
b := 1;
for i:=0 to 7do
if (abyte and (b shl i) = (b shl i)) then
bst[8-i] := '1' else
bst[8-i] := '0';
result := bst;
end;