Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The purpose of this assignment is to give you practice using C bitwise and shift operators. Your assignment is to write the following functions. The

The purpose of this assignment is to give you practice using C bitwise and shift operators. Your assignment is to write the following functions. The body of each function should consist of only 1 C statement. The statement may not be an if statement, switch statement, or a loop. You may only use the following C operators: =, * (dereferencing, not multiplication), & (bitwise and, not the address operator), |, ~, ^, <<, >>, and +. You may not need to use every operator. You are also restricted in the constants that you may use, as specified below for each problem.

The functions that you must write are described below. For each, its prototype is given, as well as a description of its proper behavior, and any limitations on the constants that you may use to write the function. Whenever a description refers to the nth bit of an integer, it refers to the bit which represents 2 n ; thus bit 0 is the rightmost (least significant) bit. The sign bit is bit 31.

gcc o hw4 hw4_test.c hw4.c ./hw4

My test code calls each of your functions on 100 test cases, and reports the number of incorrect answers produced by each function.

Each function is passed a parameter xptr, which is a pointer to an integer. There may be second parameter for some of the functions. For the sake of brevity in my descriptions below, we will assume that xptr points to an integer variable named x, and the parameter yptr (in the last problem) points to an integer variable named y.

7. void negative(int *xptr);

This function sets x to x. The only constant you may use is 1.

For example:

int x = 12;

negative(&x);

printf("%d ", x);

The output is -12.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

WHAT IS AUTOMATION TESTING?

Answered: 1 week ago

Question

What is Selenium? What are the advantages of Selenium?

Answered: 1 week ago

Question

Explain the various collection policies in receivables management.

Answered: 1 week ago