这次应该能满足你的需要<br>function bintooct(k:string):string; {二进制转换为十进制函数}<br>var<br> i,j,t:integer;<br> s:char;<br> s1,s2,s3: string;<br>begin<br> if leftstr(trim(k),1) = '0' then<br> s1 := ''<br> else<br> s1 := '-';<br> k := rightstr(trim(k),length(k)-1);<br> if pos('.',k) = 0 then<br> begin<br> t:=1;<br> j:=length(k);<br> j:=0+(ord(k[j])-ord('0'))*t;<br> for i:=length(k)-1 downto 1 do<br> begin<br> s:=k;<br> t:=t*2;<br> j:=j + ((ord(s)-ord('0'))*t);<br> end;<br> bintooct:=s1 +inttostr(j);<br> end<br> else<br> begin//带有小数位的<br> t:=1;<br> s2 := leftstr(k, pos('.',k)-1);<br> j:=length(s2);<br> j:=0+(ord(s2[j])-ord('0'))*t;<br> for i:=length(s2)-1 downto 1 do<br> begin<br> s:=s2;<br> t:=t*2;<br> j:=j + ((ord(s)-ord('0'))*t);<br> end;<br> s3 := inttostr(j);<br><br> t:=1;<br> s2 := trim(copy(k, pos('.',k)+1,length(k)));<br> j:=length(s2);<br> j:=0+(ord(s2[j])-ord('0'))*t;<br> for i:=length(s2)-1 downto 1 do<br> begin<br> s:=s2;<br> t:=t*2;<br> j:=j + ((ord(s)-ord('0'))*t);<br> end;<br> bintooct:=s1 +s3+'.'+inttostr(j);<br> end;<br>end;<br><br>function octtobin(i:Extended):string; {十进制转换为二进制函数}<br>var<br> j,k: integer;<br> m1,m2: Extended;<br> s1,s2, s3, s4:string;<br>begin<br> if i >= 0 then<br> s3 := '0'<br> else<br> begin<br> i := -i ;<br> s3 := '1';<br> end;<br> j := trunc(i);<br> s1:=' ';<br> s2:=' ';<br> while j>=2 do<br> begin<br> if (j mod 2) =1 then<br> begin<br> s1:='1'+s1;<br> j:=j div 2;<br> end<br> else<br> begin<br> s1:='0'+s1;<br> j:=j div 2;<br> end;<br> end;<br> s1:=chr(ord('0')+j) + s1;<br> s4 := Trim(s3+s1);<br> if trunc(i)<> i then<br> begin<br> s2 := '';<br> m1:= i-trunc(i);<br> k := length(floattostr(m1))-2;<br> m2 := m1 * power(10,k);<br> k := trunc(m2);<br> while k>=2 do<br> begin<br> if (k mod 2) =1 then<br> begin<br> s2:='1'+s2;<br> k:=k div 2;<br> end<br> else<br> begin<br> s2:='0'+s2;<br> k:=k div 2;<br> end;<br> end;<br> s2:=chr(ord('0')+k) + s2;<br> s4 := Trim(s4 + '.' + s2);<br> end;<br> octtobin := s4;<br>end;