Harvard University Level C Completing the Code Exceeding the Precision Programming
Question Description
Complete the code of fifigure 1 such that the following operation is achieved.
Variable test is true when x can be expressed as an n-bit, twos complement
number, and false otherwise.
Make sure that you do not exceed the precision of the int32 t representation.
Your solution cannot use loops, functions, macros or conditionals.
Also forbidden are the division, modulus and multiplication operators; as well as the
relative comparison operators (<, >, <=, >=).
You should leave unchanged the current code sub, your additional code should appear
in the region indicated by the comment fifield.
Dont forget to include a comment to identify your code with your name and banner
number.
1#include <
stdio.h
>
#include <
stdint.h
>
int
main(void
)
{
int32_t
x
,
n
, test;
printf(“Get
integer (
x
): “);
scanf(“%d
“, &
x
);
printf(“Get
num bits (
n
<32
): “);
scanf(“%d
“, &
n
);
// your assignment code begins here
// and ends here
if (
x
== test)
printf(“%d
CAN be expressed as an %
d
–
bit 2’s complement number
n
“,
x
,
n
);
else
printf(“%d
CANNOT be expressed as an %
d
–
bit 2’s complement number
n
“,
x
,
n
);
return 0;
}
Figure 1: Initial code snippet (Assign03Code.c). The only code that you need to add should
fall between the two sets of comment characters.
Have a similar assignment? "Place an order for your assignment and have exceptional work written by our team of experts, guaranteeing you A results."