Question: Using a command line arguments (main(int argc, char * argv[])), the C program you write will process the appropriate command to accomplish the required set
Using a command line arguments (main(int argc, char * argv[])), the C program you write will process the appropriate command to accomplish the required set task as follows:
a. $lab3 -p 0x5
Include a procedure, void printBits(unsigned long i), that prints the bits in i. It can be invoked from the command line using the -p switch followed by a 32-bit unsigned long integer in hexadecimal form. The minimum output should appear as follows:
0000 0000 0000 0000 0000 0000 0000 0101
b. $lab3 -u 0x7 0x55
A useful implemenetation of the mathemtical concept of set is an unsigned long treated as a set of up to 32 elements.
typedef unsigned long set;
const set empty = 0x0; /* Use hexadecimal constants */
Include a procedure that does set union using bit pattersn. Caution: Because union is a C keyword, us another name.
set Union(set a, set b);
0000 0000 0000 0000 0000 0000 0101 0111
c. $lab3 -i 0x7 0x55
While we are at it, create an intersection function:
set intersection(set a, set b);
0000 0000 0000 0000 0000 0000 0000 0101
d. $LAB3 -C 0X7
We can't forget the complement function:
set complement (set a);
1111 1111 1111 1111 1111 1111 1111 1000
e. $lab3 -r 0x7 3
C does not have a rotate operator so we will implement a right rotate function that returns the value of the unsigned long x rotated to the right by n bit positions:
unisigned long rrotate (unsigned long x, int n);
f. $lab3 -s 0x5
Include a procedure that counts the number of bits set in an unsigned long. For example, the number 5 (hexadecimal), which is 0000000000000101 (binary), has two bits set. Your output should include all three pieces of information.
g. $lab3 -m 0x55
Include a procedure that will take the bits in a number and shift them to the left end. For example, 0000 0000 0000 0000 0000 0000 0101 0101 (binary) would become 1111 0000 00000 00000 00000 0000 0000 0000 (binary).
You will need to use your printBits() function to display results of all of these functions. Make the output attractive and informative.
Hints: Build the program incrementally starting with the printBits() precedure. Implement each new function and test it completely. Make sure you use the bit operations and not string modifications, etc. to complete the task.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
