sys2.PAS 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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;
  6. BASES : array ['B'..'t'] of byte;
  7. Inp,Sout : string;
  8. Base,pos : byte;
  9. Number,cur:longint;
  10. begin
  11. WriteLn('Enter number in ''b'',''t'',''o'',''d'',''h'' systems');
  12. ReadLn(Inp);
  13. FillChar(Nums,Sizeof(NUMS),255);
  14. for pos := $30 to $39 do NUMS[chr(pos)] := pos-$30;
  15. for pos := $41 to $46 do NUMS[chr(pos)] := pos-$37;
  16. for pos := $61 to $66 do NUMS[chr(pos)] := pos-$57;
  17. Bases['b']:=2;Bases['t']:=4;Bases['o']:=8;Bases['h']:=16;Bases['d'] := 10;
  18. Bases['B']:=2;Bases['T']:=4;Bases['O']:=8;Bases['H']:=16;Bases['D'] := 10;
  19. Base := Bases[inp[ord(inp[0])]];
  20. if Base = 0 then begin WriteLn('Error in base of entred number');Halt(255);end;
  21. for pos := 1 to ord(inp[0])-1 do
  22. begin
  23. if NUMS[Inp[pos]] >= Base then
  24. begin
  25. WriteLN('Error in input string, at pos ', pos);
  26. Halt(254);
  27. end;
  28. Number := Number * base;
  29. Inc(Number,NUMS[Inp[pos]]);
  30. end;
  31. WriteLn('Введенное число в др. системах счисления:');
  32. for pos := 0 to 4 do
  33. begin
  34. base := Bases[sBases[pos]];
  35. sOut:='';
  36. cur := number;
  37. repeat
  38. insert(sNum[Cur mod base],sOut,0);
  39. Cur := cur div base;
  40. until cur = 0;
  41. WriteLn(sOut,sBases[pos]);
  42. end;
  43. end.