0% found this document useful (0 votes)
9 views1 page

Bit Reversal Function in C Assignment

The document provides instructions for a C programming assignment to write a function called BitReverse that reverses the bits of an unsigned integer. The function must take an unsigned integer pointer as a parameter and reverse the order of the bits in-place without using strings. Programming hints suggest using bitwise operators learned in class to set, clear, and read individual bits. For testing, a bitprint function is recommended to print the bit patterns before and after calling BitReverse to check that the bits are properly reversed.

Uploaded by

Gobara Dhan
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views1 page

Bit Reversal Function in C Assignment

The document provides instructions for a C programming assignment to write a function called BitReverse that reverses the bits of an unsigned integer. The function must take an unsigned integer pointer as a parameter and reverse the order of the bits in-place without using strings. Programming hints suggest using bitwise operators learned in class to set, clear, and read individual bits. For testing, a bitprint function is recommended to print the bit patterns before and after calling BitReverse to check that the bits are properly reversed.

Uploaded by

Gobara Dhan
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

BitReverse Assignment for C Programming

M. Beeson

The Assignment

The assignment is to write a function void BitReverse(unsigned *x) that reverses the bits of *x. For example, if n = 5, the bits of n are 00000000000000000000000000000101 and after we call BitReverse(&n), the bits of n should be 1010000000000000000000000000000 Explicitly, to reverse the bits of n means to make the new value of the i-th bit be the old value of the 32i1-th bit. (Assuming unsigneds are 32 bitshowever, in your code use 8*sizeof(unsigned) rather than 32, so your code does not assume anything about the size of the basic types of C.) As usual, you should put your program in three les, BitReverse.c, BitReverse.h, and main.c. You will submit only BitReverse.c. You must do this assignment without using strings in any way in BitReverse.c. This is an exercise in bitwise operations. (You can use anything you want to in your testing code in main, of course.)

Programming hints

Use what you learned in class about how to read a bit, set a bit, and clear a bit. Macros for doing those things were given in class; you can use them.

Testing your program

You will want to write a function bitprint(unsigned n) that prints out the bit pattern of an unsigned. That way, you can print out the bit pattern of an integer n, assign m = n, call BitReverse(&m), and then print out the bit patterns of n and m to see if they are the reverse of each other. Be sure to test some numbers with the highest-order bit set, not just small numbers.

You might also like