Question: BITWISE OPERATIONS IN C. After this tutorial, you will be able to: use bitwise operations to get and store information in a single bit position

BITWISE OPERATIONS IN C.

After this tutorial, you will be able to:

use bitwise operations to get and store information in a single bit position

retrieve and manipulate data from multi-dimensional arrays.

Tutorial

Download the file T03.tar from the tutorial page.

Implement the functions getBit(), setBit(), and clearBit() as prototyped.

Using the functions you just wrote, implement the function printBits() as prototyped. The output ofprintBits('A') should be:

0100 0001

Write code to accomplish the following:

Clear the bit position 6 from all values in arr.

Set the bit position 3 for all values in arr.

Output all values in arr.

Exercises

-Write a function printIntBits(int c), which prints the bits of an integer parameter.

-Write a function printIntHex(int c), which prints the hexadecimal representation of an integer parameter. Don't forget to precede the number with '0x'.

...Suppose we have an array arr[m][n], which we would like to represent as a one-dimensional arrayarrFlat[m*n] (for example, arr[5][5] would be represented as arrFlat[25])

-Write a function index(int j, int k, int n), which returns a unique and valid index in the one-dimensional array for each valid pair (j, k) of indices in the m x n 2D array.

-Write the inverse functions index_m(int i, int n) and index_n(int i, int n) which give a unique, valid pair of indices in the m x n 2D array for each valid index in the 1D array.

NOTE: if implemented correctly index(index_m(a, n), index_n(a, n), n) == a, as long as a is a valid index.

-Write similar functions for a 3D to 1D transformation.

FILE

#include

unsigned char getBit(unsigned char, int); unsigned char setBit(unsigned char, int); unsigned char clearBit(unsigned char, int); void printBits(unsigned char);

int main() {

unsigned char a = 'A';

unsigned char arr[2][3][4] = { { {62,138,241,129}, {8,221,163,159}, {91,158,169,150} }, { {15,138,251,198}, {14,211,161,158}, {77,204,188,217} } };

int i, j, k;

printBits(a); a = setBit(a, 2); a = setBit(a, 3); printBits(a); a = clearBit(a, 2); printBits(a); printf(" ");

/* implement question 4 here */

return 0; }

unsigned char getBit(unsigned char c, int n) {

}

unsigned char setBit(unsigned char c, int n) {

}

unsigned char clearBit(unsigned char c, int n) {

}

void printBits(unsigned char c) {

}

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!