Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program conv_bin_hex;
- uses wincrt;
- var
- ch:string;
- function verif(ch:string):Boolean;
- Var i:integer;
- begin
- i:=1;
- while (ch[i] in ['1','0']) AND (i <= length(ch)) do
- i:=i+1;
- verif:= i > length(ch);
- end;
- procedure saisie(var ch:string);
- begin
- repeat
- write('ch=');
- readln(ch);
- until (ch <> '') AND (verif(ch));
- end;
- function conv_10_b(x:integer;b:byte):string;
- var R:integer;
- ch,ch1:string;
- begin
- ch:='';
- Repeat
- R:= X mod b;
- if R>= 10 then ch1:=ord(R+55)
- else str(R,ch1);
- ch:=ch1+ch;
- x:= x div b;
- until x = 0;
- end;
- function conv(ch:string):string;
- Var
- ch_hex,bloc:string;
- i,x,e,bloc_dec:integer;
- begin
- ch_hex:='';
- repeat
- i:=length(ch);
- bloc:='';
- Repeat
- if length(ch) >= 4 then
- begin
- bloc:=ch[i] + bloc;
- i:=i-1;
- end
- else
- Repeat
- ch:='0'+ ch;
- until length(ch) = 4;
- until length(bloc) = 4;
- val(bloc,x,e);
- bloc_dec:=conv_bloc(x);
- ch_hex:= conv_10_b(x,15) + ch_hex;
- delete(ch,i,4);
- until ch='';
- end;
- begin
- saisie(ch);
- write('la conversion en hexadeciaml est : ',conv(ch));
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement