The following is an incomplete Pascal function to convert a given decimal…
PYQ GATE 1995Modified — slightly modified from the official paper; see the solution
The following is an incomplete Pascal function to convert a given decimal integer (in the range -8 to +7) into a binary integer in 2’s complement representation. Determine the expression A, B, C that complete program.
function TWOSCOMP (N:integer):integer;
var
REM, EXPONENT:integer;
BINARY :integer;
begin
if(N>=-8) and (N<=+7) then
begin
if N<0 then N := A;
BINARY:=0;
EXPONENT:=1;
while N<>0 do
begin
REM:=N mod 2;
BINARY:=BINARY + B*EXPONENT;
EXPONENT:=EXPONENT*10;
N := C
end
TWOSCOMP:=BINARY
end
end;
Sign up free to check your answer
Sign up freeLoading lesson…

