| 12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- const
- sNum : array [0..15] of char = ('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
- sBases : array [0..4] of char = ('d','b','t','o','h');
- var
- NUMS : array ['0'..'f'] of byte;
- BASES : array ['B'..'t'] of byte;
- Inp,Sout : string;
- Base,pos : byte;
- Number,cur:longint;
- begin
- WriteLn('Enter number in ''b'',''t'',''o'',''d'',''h'' systems');
- ReadLn(Inp);
- FillChar(Nums,Sizeof(NUMS),255);
- for pos := $30 to $39 do NUMS[chr(pos)] := pos-$30;
- for pos := $41 to $46 do NUMS[chr(pos)] := pos-$37;
- for pos := $61 to $66 do NUMS[chr(pos)] := pos-$57;
- Bases['b']:=2;Bases['t']:=4;Bases['o']:=8;Bases['h']:=16;Bases['d'] := 10;
- Bases['B']:=2;Bases['T']:=4;Bases['O']:=8;Bases['H']:=16;Bases['D'] := 10;
- Base := Bases[inp[ord(inp[0])]];
- if Base = 0 then begin WriteLn('Error in base of entred number');Halt(255);end;
- for pos := 1 to ord(inp[0])-1 do
- begin
- if NUMS[Inp[pos]] >= Base then
- begin
- WriteLN('Error in input string, at pos ', pos);
- Halt(254);
- end;
- Number := Number * base;
- Inc(Number,NUMS[Inp[pos]]);
- end;
- WriteLn('Введенное число в др. системах счисления:');
- for pos := 0 to 4 do
- begin
- base := Bases[sBases[pos]];
- sOut:='';
- cur := number;
- repeat
- insert(sNum[Cur mod base],sOut,0);
- Cur := cur div base;
- until cur = 0;
- WriteLn(sOut,sBases[pos]);
- end;
- end.
|