Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const digits:array [0..1] of char = ('0','1');
- function tobin(x, a:longint):string;
- var res,s:string; d:0..1; i,j:integer;
- begin
- i:=0;
- res:='';
- while (x<>0) do begin
- d:=x mod 2;
- res:=digits[d]+res;
- x:=x div 2;
- i:=i+1;
- end;
- s:='';
- for j:=i to a-1 do s:=s+'0';
- tobin:=s+res;
- end;
- function todec(x:string):longint;
- const digits:array [0..1] of char = ('0','1');
- var res,ves:longint; i,j:byte;
- begin
- res:=0; ves:=1;
- for i:=length(x) downto 1 do begin
- j:=0;
- while (digits[j]<>x[i]) do inc(j);
- res:=res+ves*j;
- ves:=ves*2;
- end;
- todec:=res;
- end;
- function tozndec(x:string; a:longint):longint;
- const digits:array [0..1] of char = ('0','1');
- var res,ves:longint; i,j:byte;
- begin
- res:=0; ves:=1;
- for i:=length(x) downto 1 do begin
- j:=0;
- while (digits[j]<>x[i]) do inc(j);
- res:=res+ves*j;
- ves:=ves*2;
- end;
- if res > trunc(2**(a-1)) then res:=res-trunc(2**a);
- tozndec:=res;
- end;
- var
- a,b,c,d,e:longint;
- s,s1,s2,s3:string;
- begin
- readln(a,b,c);
- d:=(b+c) mod trunc(2**a);
- e:=(b-c) mod trunc(2**a);
- if b<0 then b:=b+trunc(2**a);
- if c<0 then c:=c+trunc(2**a);
- if d<0 then d:=d+trunc(2**a);
- if e<0 then e:=e+trunc(2**a);
- s:=tobin(b, a);
- s1:=tobin(c, a);
- s2:=tobin(d, a);
- s3:=tobin(e, a);
- //writeln('+ ', s, ' ', s1, ' ', s2, ' ', todec(s2), ' ', tozndec(s2,a));
- //writeln('- ', s, ' ', s1, ' ', s3, ' ', todec(s3), ' ', tozndec(s3,a));
- writeln('+ ', copy(s, length(s) - a, a), ' ', copy(s1, length(s1) - a, a), ' ', s2, ' ', todec(s2), ' ', tozndec(s2,a));
- writeln('- ', copy(s, length(s) - a, a), ' ', copy(s1, length(s1) - a, a), ' ', s3, ' ', todec(s3), ' ', tozndec(s3,a));
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement