Question: Write a function in C that begins: int rotate_left (int num, int n) { This function should left-shift num by n positions, where the high-order
Write a function in C that begins:
int rotate_left (int num, int n) {
This function should left-shift num by n positions, where the high-order bits are reintroduced as the loworder bits.
Here are two examples of a circular shift operation using a short bit pattern, rather than a full integer.
1000 0001 circular shift 1 yields 0000 0011
0110 1011 circular shift 3 yields 0101 1011

ALGORITHM DEVELOPMENT Pseudocode: main do print a request and read an integer Number if Number is not equal to 0 print a request and read the number of positions to shift print the Original Number print the bit pattern of Original Number call rotate_left and return Shifted Number print the bit pattern of Shifted Number print the Shifted Number while Number is not equal to 0 void bitprint (int num) determine the number of bytes in an integer word and change it to number of bits. create the mask with a 1 in the left-most position loop thru each bit using count variable set the bit to 1 or 0 depending on the result of (num & mask) printf the one bit if the count is a multiple of four print a space return int rotateleft (int num, int n) find the number of bytes in an int word and change it to number of bits create the mask with a 1 in the left-most position loop thru the number-of-bits to shift left Save the left bit in variable bit. Left shift the num by one Add the isolated bit in bit variable onto the right of num (This can be done with a +,, or ) return num
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
