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
- if x<0 then x:=x+trunc(2**a);
- 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;
- f1,f2,f3,f4,f5,f6,f7,f8:byte;
- begin
- readln(a,b,c);
- d:=(b+c) mod trunc(2**a);
- e:=(b-c) mod trunc(2**a);
- s:=tobin(b, a);
- s1:=tobin(c, a);
- s2:=tobin(d, a);
- s3:=tobin(e, a);
- if todec(s2)=0 then f1:=1 else f1:=0;
- if todec(s3)=0 then f5:=1 else f5:=0;
- if tozndec(s2,a)<0 then f2:=1 else f2:=0;
- if tozndec(s3,a)<0 then f6:=1 else f6:=0;
- if ((b>=0) and (c>=0)) or (((b*c)<=0) and ((b+c)<0)) then f3:=0 else f3:=1;
- if ( ((b<0) and (c>=0)) or ((b>=c) and (c>=0)) or ((0>b) and (b>=c)) ) then f7:=0 else f7:=1;
- if ( ((b+c) >= (2**(a-1))*(-1)) and ((b+c) < (2**(a-1))) ) then f4:=0 else f4:=1;
- if ( ((b-c) >= (2**(a-1))*(-1)) and ((b-c) < (2**(a-1))) ) then f8:=0 else f8:=1;
- //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), ' ', f1,f2,f3,f4);
- writeln('- ', copy(s, length(s) - a, a), ' ', copy(s1, length(s1) - a, a), ' ', s3, ' ', todec(s3), ' ', tozndec(s3,a), ' ', f5,f6,f7,f8);
- writeln;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement