Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program BinairOuPas;
- {$APPTYPE CONSOLE}
- uses
- SysUtils,ShellAPI;
- function bintodec(b,k:longint):integer;
- begin { breakpoint condition}
- if b=0 then
- bintodec:=0
- else
- bintodec:=bintodec(b div 10, k*2)+b mod 10 * k; {recursive call}
- end;
- var
- choix : string;
- a,b,d,e,f:integer;
- c:array[1..255] of integer;
- begin
- { TODO -oUser -cConsole Main : placez le code ici }
- Writeln('------------------------------------------');
- Writeln(' Convertiseur binaire by David ');
- Writeln('------------------------------------------');
- Writeln('Bonjour, voici les choix disponnibles :');
- Writeln('1. Convertir de decimal en binaire');
- Writeln('2. Convertir de binaire en decimal');
- Writeln;
- Write('Votre choix : ');
- Readln(choix);
- if choix = '1' then
- begin
- Writeln;
- Writeln('Vous avez choisis la conversion binaire, veuillez indiquer votre nombre');
- Write('Votre nombre : ');
- Readln(a);
- if a<=1 then write(a) else
- repeat
- b:=b+1;
- d:=trunc(a/2);
- c[b]:=a mod 2;
- if d<=1 then
- begin
- b:=b+1;
- c[b]:=d;
- end;
- a:=d;
- until d<=1;
- for e:=b downto 1 do
- begin
- write(c[e]);
- end;
- Writeln;
- Writeln('Appuyer sur une touche pour continuer');
- Readln
- {Fonction de conversion de decimal en binaire}
- end
- else if choix = '2' then
- begin
- Writeln('Vous avez choisis la conversion decimal, veuillez indiquer votre nombre');
- Write('Votre nombre : ');
- Readln(b);
- write;
- write('Votre nombre converti : ');
- writeln(bintodec(b,1)); {Appel de la fonction de covnersion}
- {Fonction de conversion de binaire en decimal}
- writeln('Appuyer une touche pour continuer');
- Readln;
- end
- else
- begin
- Writeln('Vous n''avez pas indiquer de chiffre, appuyer sur une touche pour fermer l''application');
- Readln;
- end
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement