进制的转换!

lxxtcw20 2003-12-27 09:11:14
我是个初学pascal的新手,对这些都不知道如何写程序!
我现在有个题目要大家帮个忙!
谢谢·!
题目:编写一个程序程序,将输入的一个数转换为所要求的娄输出,
比如:输入16 2;则要输出10000(base2);
注:前面的16是10 进制数,后面的2是要转换成的进制数!
现在要求编写的程序就是写一个程序,使得输入的“2”在2到20之内的转换!

谢谢各位高手的帮忙!
...全文
51 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
foxnt 2003-12-29
  • 打赏
  • 举报
回复
10 <-> 2 转换
function IntToBin(i: longint): string;
var
quotient: integer;
remainder: string;
begin
if i < 0 then Exit;
quotient := i div 2;
while quotient > 0 do
begin
remainder := IntToStr(i mod 2) + remainder;
i := quotient;
quotient := i div 2;
end;
remainder := IntToStr(i mod 2) + remainder;
Result := remainder;
end;

function BinToInt(bin: pChar): extended;
var
len, i: integer;
begin
Result := 0;
if bin <> nil then
begin
len := Length(bin);
i := len;
while bin^ <> #0 do
begin
if (ord(bin^) > 57) or (ord(bin^) < 48) then
begin
Result := 0;
Exit;
end;
i := i - 1;
Result := Result + StrToInt(bin^) * IntPower(2, i);
inc(bin);
end;
end;
end;
fj218 2003-12-28
  • 打赏
  • 举报
回复
function conver(const m,n:integer):string;
const
Table: array [0..19] of char = '0123456789ABCDEFGHIJ';
var
a,b:integer;
begin
Result:='';
a:=m;
b:=n;
repeat
result:=table[a mod b]+result;
a:=a div b;
until a=0;
end;

16,742

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 语言基础/算法/系统设计
社区管理员
  • 语言基础/算法/系统设计社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧