Question

In this assignment, you must complete the 5 functons below. Each function's body must consist of...

In this assignment, you must complete
the 5 functons below. Each function's body
must consist of just a single C statement.
Furthermore, the statement must not be a control
statement, such as if, switch, or any kind of loop.
For each problem, you are also restricted to the
operators and constants as specified.
*/

/* 1. Write a function which zeros a variable x. A
pointer to x is passed as a parameter. YOU MAY
USE NO CONSTANTS in this function, and must
restrict yourself to using the assignment operator,
the dereferencing operator, and one or more of
the bitwise operators.
*/

void zero(int *xptr) {

}

/* 2. Write a function to set x to be the maximum unsigned long
integer. The parameter passed to the function is a
pointer to x. You may only use the constant 0 in
this function, and must restrict yourself to using
the assignment operator, the dereferencing operator,
and the bitwise operators.
*/

void maximum(unsigned long *xptr) {

}

/* 3. Write a function to set x to be the minimum long
integer. The parameter passed to the function is a
pointer to x. You may only use the constants 0-63 in
this function, and must restrict yourself to using
the assignment operator, the dereferencing operator,
the bitwise operators, and the shift operators.
*/


void minimum(long *xptr) {

}

/* 4. Write a function which sets the integer x to negative x.
The parameter passed to the function is a pointer to x.
You may only use the constant 1 in this function,
and must restrict yourself to the assignment operator,
the dereferencing operator, the bitwise operators, and
the + operator.
*/

void negative(int *xptr) {

}

/* 5. Write a function called set_byte. It is passed 3
parameters: a pointer to an unsigned integer x, an
index i, and a new value v for the byte.
The function should change the ith byte of x to
v. Byte 0 is x's least significant byte; byte 1
is the next least significant byte, etc.; byte 3
is x's most significant byte. You may only use the
constants 0-4 in this function, and must restrict
yourself to the the assignment operator, the
dereferencing operator, multiplication, bitwise
operators and shift operators.
*/

void set_byte(unsigned int *xptr, int i, char v) {

}

int main() {
int x;
int *xptr = &x;
long l;
long *lptr = &l;
unsigned long ul;
unsigned long *ulptr = &ul;

zero(xptr);
printf("zero %d\n", x);
maximum(ulptr);
printf("max %#lx %lu\n", ul, ul);
minimum(lptr);
printf("min %#lx %ld\n", l, l);
x = 3;
negative(xptr);
printf("negative %d\n", x);
x = 15;
set_byte(xptr, 2, 15);
printf("%#x\n", x);
}

0 0
Add a comment Improve this question Transcribed image text
Know the answer?
Add Answer to:
In this assignment, you must complete the 5 functons below. Each function's body must consist of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • This daily will allow you to practice more with the bit wise operators and shifts. Consider...

    This daily will allow you to practice more with the bit wise operators and shifts. Consider the following modification of the main program from daily 3: #include void set_flag(unsigned int* flag_holder, int flag_position); void unset_flag(unsigned int * flag_holder, int flag_position); int check_flag(unsigned int flag_holder, int flag_position); void display_32_flags(unsigned int flag_holder); int main(int argc, char* argv[]) { unsigned int flag_holder = 0; set_flag(&flag_holder, 3); set_flag(&flag_holder, 16); set_flag(&flag_holder, 31); display_32_flags(flag_holder); unset_flag(&flag_holder, 31); unset_flag(&flag_holder, 3); set_flag(&flag_holder, 9); display_32_flags(flag_holder); return 0; } Write the...

  • (Packing Characters into an Integer) The left-shift operator can be used to pack four character values into a four-byt...

    (Packing Characters into an Integer) The left-shift operator can be used to pack four character values into a four-byte unsigned int variable. Write a program that inputs four characters from the keyboard and passes them to function packCharacters. To pack four characters into an unsigned int variable, assign the first character to the unsigned intvariable, shift the unsigned int variable left by 8 bit positions and combine the unsigned variable with the second character using the bitwise inclusive OR operator....

  • C programming lab: Description: In this lab you will write a program that will contain two...

    C programming lab: Description: In this lab you will write a program that will contain two functions, setlsbs() and getlsbs(). These functions will use bitwise operators to embed and extract "hidden" bits in a character array. Write a program to test your functions as follows: Obtain a random number seed from the command line of your program using command line arguments. Initialize an array p of 8 unsigned char with random numbers from 0 to 255 Initialize a separate unsigned...

  • write C code that uses pointers, arrays, and C strings. 3. Write a function called pow_xy....

    write C code that uses pointers, arrays, and C strings. 3. Write a function called pow_xy. The function should be passed 2 parameters, as illustrated in the prototype below. int pow_xy(int *xptr, int y); Assuming that xptr contains the address of variable x, pow_xy should compute x to the y power, and store the result as the new value of x. The function should also return the result. Do not use the built-in C function pow. For the remaining problems,...

  • In C, thanks. #include <stdio.h> void set-flag (unsigned int* flag-holder , int flag-position); void unset-flag (unsigned...

    In C, thanks. #include <stdio.h> void set-flag (unsigned int* flag-holder , int flag-position); void unset-flag (unsigned int * flag-holder, int flag-position); int check-flag (unsigned int flag-holder , int flag-position); void display -32_flags (unsigned int flag-holder); int main(int argc, char* argv (1) unsigned int flag -holder = 0; set-flag (& flag-holder, 3); set-flag (& flag-holder, 16); set-flag (& flag-holder, 31); display-32-flags (flag-holder); unset-flag(& flag-holder , 31); unset-flag (& flag-holder, 3); set-flag (& flag-holder , 9); display-32-flags (flag-holder ); return 0; Write...

  • Topics: Arrays in C. For this assignment, you will write a C program that uses its...

    Topics: Arrays in C. For this assignment, you will write a C program that uses its first command line parameter to compute and display a histogram of characters that occur in it. Requirements: Your program must compile and run correctly using the gcc compiler on ale. You must write the corresponding function definitions for the following function prototypes: // set all elements of the histogram to zero void init_histogram(int histo[]); // construct the histogram from string void cons_histogram(char string[], int...

  • IntList Recursion Assignment Specifications: You will add some additional recursive functions to your IntList class as...

    IntList Recursion Assignment Specifications: You will add some additional recursive functions to your IntList class as well as make sure the Big 3 are defined. IntNode class I am providing the IntNode class you are required to use. Place this class definition within the IntList.h file exactly as is. Make sure you place it above the definition of your IntList class. Notice that you will not code an implementation file for the IntNode class. The IntNode constructor has been defined...

  • Write a program that allows the user to enter an unsigned integer (the maximum value of...

    Write a program that allows the user to enter an unsigned integer (the maximum value of an unsigned 4-byte int is 232 = 4,294,967,296) and reverses its format (from little to big endian, or vice versa). Print out the user-entered number in hexadecimal and binary, reverse the endianness, and print the reverse in hexadecimal and binary. Integers in most machine architectures are represented in little endian format: the least significant byte is stored in the smallest address; for instance, the...

  • C Programming write two functions, similar to what you see in the sample program. The first will ask the user to enter some information (I have included the type in parentheses) First Name (char[]) L...

    C Programming write two functions, similar to what you see in the sample program. The first will ask the user to enter some information (I have included the type in parentheses) First Name (char[]) Last Name (char[]) Age (int) Height in Inches (double) Weight in Pounds (double) You will use pass-by-reference to modify the values of the arguments passed in from the main(). Remember that arrays require no special notation, as they are passed by reference automatically, but the other...

  • C++ The Function's Specification You will be writing a function with this specification: void quicksort void*...

    C++ The Function's Specification You will be writing a function with this specification: void quicksort void* base size t n, size t bytes, int compar (const void* const void*) Precondition base is a pointer to the first component of an array with at least n elements The component type of the array may be any type at all, and the parameter bytes must be the number of bytes in each component of the array. The fourth parameter compar, must be...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT