Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Program covertion;
- Uses Wincrt;
- Var
- b1,b2: Integer;
- ch1: String;
- x:char;
- Function verif (ch:String): Boolean;
- Var
- i: Integer;
- test:Boolean;
- Begin
- i := 0;
- Repeat
- i := i+1;
- test := ch[i] In['A'..'F','0'..'9'];
- Until (i=Length(ch)) Or (test=False);
- verif:=test;
- End;
- Function convb1 (ch:String;x1:integer): Integer;
- Var
- s,i,p,e,x:Integer;
- Begin
- p := 1;
- s := 0;
- For i:=Length(ch) downto 1 Do
- Begin
- if (ch[i] in ['A'..'F']) Then
- begin
- s:=s+p*ord(ch[i])-55;
- p:=p*x1 ;
- end
- else
- begin
- val (ch[i],x,e);
- s:=s+p*x;
- p:=p*x1 ;
- end;
- End;
- convb1:=s;
- End;
- Procedure saisie (Var ch1:String;Var b1,b2:Integer);
- Begin
- Repeat
- ClrScr;
- Write ('Saisir la premiere base: ');
- Readln (b1);
- Write ('Saisir la deuxieme base: ');
- Readln (b2);
- if (b2=b1) Then
- begin
- writeln ('Vous avez saisi la meme base deux fois !');
- delay (1500);
- end;
- if (not (b1 in [2,8,10,16])) or (not(b2 in [2,8,10,16])) Then
- begin
- writeln ('Verifiez les bases saisies!');
- delay (1500);
- end;
- Until (2<=b2) And (b2<=16) And (2<=b1) And (b1<=16) and (b1 in [2,8,10,16]) and (b2 in [2,8,10,16]) and (b2<>b1);
- Repeat
- Write ('Saisir la chaine: ');
- Readln (ch1);
- Until verif (ch1);
- End;
- Function convb2 (b2,n:integer): String;
- Var
- i: Integer;
- ch,ch1: String;
- Begin
- ch := '';
- Repeat
- If (n Mod b2>9) Then
- Begin
- i := 55+n Mod b2;
- ch := ch+Chr(i);
- n := n Div b2;
- End
- Else
- Begin
- Str (n Mod b2,ch1);
- ch := ch+ch1;
- n := n Div b2;
- End;
- Until (n=0);
- ch1 := '';
- For i:=Length(ch) Downto 1 Do
- ch1 := ch1+ch[i];
- convb2 := ch1;
- End;
- function conv (ch:string;b1,b2:integer):string;
- Var
- x:integer;
- Begin
- x:=convb1 (ch,b1);
- ch:=convb2 (b2,x);
- conv:=ch;
- end;
- Begin
- Repeat
- ClrScr;
- saisie (ch1,b1,b2);
- Writeln ('(',ch1,')',b1,'=(',conv(ch1,b1,b2),')',b2);
- writeln ('Voulez vous continuer? O/N');
- readln (x);
- until (x='N') or (x='n');
- End.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement