Question: 2.Write code for the function with the following prototype: /* * Return 1 when x can be represented as an n-bit, 2s complement number; 0

2.Write code for the function with the following prototype:

/* * Return 1 when x can be represented as an n-bit, 2s complement number; 0 otherwise * Assume 1 <= n <= 64 * Examples: problem2(5,3) = 0, problem2(-4,3) = 1 * Legal ops: ! ~ & ^ | + << >> */ int problem2(long int x, long int n); 

Assumptions

Integers are 64-bits long and represented in twos-complement form.

Right shifts of signed data are performed arithmetically.

Forbidden

Casting, either explicit or implicit.

Relative comparison operators (<, >, <=, and >=).

Division, modulus, and multiplication.

Conditionals(if or ? :), loops, switch statements, function calls, and macro invocations.

Casting, either explicit or implicit.

Legal Operations

Each problem has a list of which operations you are allowed to utilize

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!