SYSTEM.PAS 956 B

1234567891011121314151617181920212223
  1. const
  2. sNum : array [0..15] of char = ('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
  3. sBases: array [0..4] of char = ('d','b','t','o','h');
  4. var
  5. NUMS : array ['0'..'F'] of byte; BASES: array ['b'..'t'] of byte;
  6. Inp,Sout : string; Base,pos : byte; Number, cur:longint;
  7. begin
  8. ReadLn(Inp);
  9. for pos := $30 to $39 do NUMS[chr(pos)] := pos-$30;
  10. for pos := $41 to $46 do NUMS[chr(pos)] := pos-$37;
  11. Bases['b']:=2;Bases['t']:=4;Bases['o']:=8;Bases['h']:=16;Bases['d'] := 10;
  12. Base := Bases[inp[ord(inp[0])]];
  13. for pos := 1 to ord(inp[0])-1 do
  14. begin Number := Number * base; Inc(Number,NUMS[Inp[pos]]); end;
  15. WriteLn('Введенное число в др. системах счисления:');
  16. for pos := 0 to 4 do
  17. begin
  18. base := Bases[sBases[pos]]; sOut:=''; cur := number;
  19. repeat insert(sNum[Cur mod base],sOut,0); Cur := cur div base;
  20. until cur = 0;
  21. WriteLn(sOut,sBases[pos]);
  22. end;
  23. end.