1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
| program convertion;
uses wincrt;
type fe=file of integer;
var
f:text;
f1:fe;
function verif(ch:string):boolean;
var i,v,e:integer;
test:boolean;
begin
i:=1;
repeat
i:=i+1;
val(ch[i],v,e);
if (v in[0,1])then
test:=true
else
test:=false;
until (i=length(ch)) or (test=false);
verif:=test;
end;
{procedure saisie(var ch:string);
begin
repeat
write('ch : ');
readln(ch);
until (verif(ch));
end;}
procedure remplir_f(var f:text);
var ch:string;
begin
rewrite(f);
while (not eof(f)) do
begin
repeat
write('ch : ');
readln(ch);
until (verif(ch));
writeln(f,ch);
end;
close(f);
end;
function puis(x,y:integer):integer;
begin
if y=0 then
puis:=1
else
puis:=puis(x,y-1)*x;
end;
function conv2_10(ch:string):integer;
var i,s,v,e:integer;
begin
s:=0;
for i:=1 to length(ch) do
begin
val(ch[i],v,e);
s:=s+(puis(2,length(ch)-i))*v;
end;
conv2_10:=s;
end;
procedure remplir_f1(var f:text;var f1:fe);
var n:integer;
ch:string;
begin
rewrite(f1);
reset(f);
while (not eof(f)) do
begin
readln(f,ch);
n:=conv2_10(ch);
write(f1,n);
end;
close(f);
close(f1);
end;
procedure affiche(var f1:fe);
var nb:integer;
begin
reset(f1);
while (not eof(f)) do
begin
read(f,nb);
writeln(nb);
end;
close(f1);
end;
begin
assign(f,'C:\Users\Bouzezi\Desktop\bac\prog\convertion entre base\convertion_2_10\par un fichier\bin.txt');
assign(f1,'C:\Users\Bouzezi\Desktop\bac\prog\convertion entre base\convertion_2_10\par un fichier\dec.dat');
{saisie(ch);
n:=conv2_10(ch);
write(ch, ' EN DECIMALE : ',n);}
remplir_f(f);
remplir_f1(f,f1);
affiche(f1);
end. |
Partager