Prosím potřeboval bych poradit jak na převod mezi soustavami dec>bin,hex bin>dec,hex hex>dec,bin
a to jestli by mi někdo tady nepostnul kód s těmato třema převodama.
Děkuji.
Fórum › Pascal
Převod mezi jednotkama

program prevodSustav;
uses crt;
var cislo:string;
vstup,vystup:integer;
koniec:char;
label zaciatok;
function toDecimal(sustava:integer;cislo:string):integer;
var i,vysledok,pom,mocnina:integer;
begin
vysledok:=0;
mocnina:=1;
for i:=Length(cislo) downto 1 do
begin
if (ord(cislo[i])<=ord('9')) and (ord(cislo[i])>=ord('0')) then
begin
pom:=ord(cislo[i])-ord('0');
if pom>=sustava then
begin
writeln('Cislo ktore ste zadali nie je z danej sustavy!Opakujte volbu prosim');
goto zaciatok;
end;
end
else if (ord(lowercase(cislo[i]))>=ord('a')) and (ord(lowercase(cislo[i]))<=ord('z')) then
begin
pom:=ord(lowercase(cislo[i]))-ord('a')+10;
if pom>=sustava then
begin
writeln('Cislo ktore ste zadali nie je z danej sustavy!Opakujte volbu prosim');
goto zaciatok;
end;
end;
pom:=pom*mocnina;
mocnina:=mocnina*sustava;
vysledok:=vysledok+pom;
end;
toDecimal:=vysledok;
end;
function fromDecimal(sustava:integer;cislo:integer):string;
var vysledok:string;
pom,i,j:integer;
znak:char;
begin
i:=0;
while cislo<>0 do
begin
i:=i+1;
pom:=(cislo)mod(sustava);
cislo:=(cislo)div(sustava);
if pom<=9 then vysledok:=vysledok + chr(pom+ord('0'))
else if pom>=10 then vysledok:=vysledok + chr(ord('A')+(pom-10));
end;
for j:=1 to (i)div(2) do
begin
znak:=vysledok[i-j+1];
vysledok[i-j+1]:=vysledok[j];
vysledok[j]:=znak;
end;
fromDecimal:=vysledok;
end;
begin
repeat
clrscr;
writeln(' System Conventer 2009');
writeln(' ***Created by Luk***');
writeln();
zaciatok:
write('Zadajte vstupnu sustavu: ');
readln(vstup);
write('Zadajte cislo: ');
readln(cislo);
write('Zadajte vystupnu sustavu: ');
readln(vystup);
cislo:=fromDecimal(vystup,toDecimal(vstup,cislo));
write('Vysledne cislo je ');
writeln(cislo);
writeln('Znovu? a/n');
koniec:=readkey;
until koniec='n';
end.
Premeni cislo z lubovnej do lubovonej sustavy

Přidej příspěvek
Toto téma je starší jak čtvrt roku – přidej svůj příspěvek jen tehdy, máš-li k tématu opravdu co říct!
Ano, opravdu chci reagovat → zobrazí formulář pro přidání příspěvku
×Vložení zdrojáku
×Vložení obrázku
×Vložení videa
Aktuálně jsou podporována videa ze serverů YouTube, Vimeo a Dailymotion.
×






























































Uživatelé prohlížející si toto vlákno
Uživatelé on-line: 0 registrovaných, 32 hostů
Podobná vlákna
Převod mezi soustavami — založil edor
Převod mezi soutavami — založil lotrman
Převod mezi číselnými soustavami — založil Alex
Převod mezi číselnými soustavami — založil Hnusný_Slimák
Výstup v programu pro převod mezi soustavami — založil Mordor
Moderátoři diskuze