- 分享
- 2009-09-13 20:49:40 @
十进制和二进制的转换
FP的程序
哪位大牛教一下
5 条评论
-
prince_hao LV 10 @ 2009-09-13 20:49:41
program backbinary;
var a:array[0..50]of integer;
s:string;
mult,ans:int64;
i:integer;
begin
readln(s);
for i:=length(s) downto 1 do
a[length(s)-i+1]:=ord(s[i])-ord('0');
mult:=1;
for i:=1 to length(s) do
begin
inc(ans,mult*a[i]);
mult:=mult*2;
end;
writeln(ans);
end. -
2009-09-13 20:16:00@
纠个错
倒数第四行
for ii:= i downto 1 do
应该改为
for ii:= i-1 downto 1 do -
2009-07-17 20:56:19@
不情之请
感谢2L的
是否方便教一下 二进制转化十进制 啊 -
2009-07-15 22:45:04@
这种题目应该自己想
-
2009-07-15 21:31:56@
可能有点麻烦......
var
a:array[1..100] of integer;
i,ii,x,y,n:integer;
begin
readln(n);
y:=n div 2;
x:=n mod 2;
a[1]:=x;
i:=2;
while y0 do
begin
x:=y mod 2;
y:=y div 2;
a[i]:=x;
i:=i+1;
end;
for ii:=i downto 1 do
write(a[ii]);
readln
end.
- 1