Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please write in c, thanks. Setting a bit to 1 Write a function that accepts as input an unsigned char, and an integer bitNum (range

image text in transcribedimage text in transcribedimage text in transcribed

Please write in c, thanks.

Setting a bit to 1 Write a function that accepts as input an unsigned char, and an integer bitNum (range 0-7) and using the "shift" and "or" operators sets the bit at position bitNum to 1. The function returns modified character For example, if the bit sequence of a char is 00010100 and bitNum5 then the answer should return 00110100 Function prototype unsigned char setBit(unsigned char c, int bitNum); Instructions: This can be accomplished in a similar way to exercise 2 above Clearing a bit Write a function that accepts as input an unsigned char, and an integer bitNum (range 0-7) and using the "shift", "and" and "not" operators clears the bit at position bitNum (namely, sets the bit at position bitNum to 0). The function returns modified character. Note, that no assumption is made whether the bit sition bitNum i For example, if the bit sequence of a char is 00010100 and bitNum4 then the answer should return 00000100 unsigned char clearBit(unsigned char c, int bitNum); Printing bits iteratively Write a function that accepts as input an unsigned char and prints the bits of the character. The function should print the bits iteratively (namely using a "for loop"). The function needs to print the bits that the MSB (bit 7) is printed first. Use the following statements when printing 1. To print a 0 use - printf("O"); 2. To print a 1 use - printf("1"); 3. To go the next line use printf("In"); Note that you can combine the new line with any other printing statement e.g., to print a 0 on the screen and skip to the next line use printf("O "); For example if the c is 'A' then the function output should be 01000001 Function prototype void printBitslterative(unsigned char c); Instructions Here the function will need to iterate on all the bits. There are several ways of accomplishing it. Below is one way of doing it. Option 1: Here you will use the isBitSet() function that you coded. 1. Loop (using a for loop) on all the possible bits (bits 0-7) and check each bit whether it is set a. If the bit is set, then print a 1 otherwise print a 0 Printing bits recursively Write a recursive function that accepts as input an unsigned char and using the functions above prints the bits of the character. In this printing scheme leading O's are not printed. Namely ifc4 then the function will print 100. For example if the c is 'A' then the function output should be 1000001 Function prototype void printBitsRecursive(unsigned char c); pseudo code // base case - print the write most bit if c is either 0 or 1 // if c is either 0 or 1 then print 0 or 1 depending on the state of the least significant bit (LSB) // recursive step // call the function recursively while using right shift by 1 on c // print the LSB of C (either 0 or 1) // note that here the "work of the recursive step" is carried out after the recursive step

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

Beyond Big Data Using Social MDM To Drive Deep Customer Insight

Authors: Martin Oberhofer, Eberhard Hechler

1st Edition

0133509796, 9780133509793

More Books

Students also viewed these Databases questions

Question

List out some inventory management techniques.

Answered: 1 week ago

Question

=+ a. a family deciding whether to buy a new car

Answered: 1 week ago

Question

=+10. How are inflation and unemployment related in the short run?

Answered: 1 week ago