C2A2E2 (5 points - C++ Program)
Instructor-supplied file and it will use the code you write. File C2A2E2_CountIntBitsF.cpp must contain an exact copy of the CountIntBitsF function you wrote. File C2A2E2_Rotate.cpp must contain function Rotate and no #define or #include. Rotate syntax: unsigned Rotate(unsigned object, int count); Parameters: object - the value to rotate count - the number of bit positions & direction to rotate: negative => left and positive => right Synopsis: Produces the value of parameter object as if it had been rotated by the number of positions and in the direction specified by count Return: the rotated value The Rotate function must: 1. Call CountIntBitsF once and only once to determine the number of bits in parameter object 2. Not call any function other than CountIntBitsF. 3. Not assume a char/byte contains 8 or any other specific number of bits. 4. Not use loops, recursion, sizeof, macros, or anything from any header file. 5. Not implement a special case for handling a count value of 0. 6. Not display anything Here are some examples for a 32-bit type unsigned int: Function Call Return Function Call Return rightrotate Value (left rotate) Value Rotate(0xa701, 1) 0x80005380 Rotate(0xa701, -1) 0x14e02 Rotate(0xa701, 225) 0x80005380 Rotate(0xa701, 225) 0x14e02 Rotate(0xa701, 1697) 0x80005388 Rotate(0xa701, -1697) 0x14e02 Rotate(0xdefacebd, 2) 0x77beb3af Rotate(0xdefacebd, -2) 0x7beb3af7 Rotate(0xdefacebd194) 0x77beb3af Rotate(0xdefacebd) 0x7beb3af7 Rotate(0xdefacebd5378) 0x77beb3af Rotate(0xdefacebd, -5378) 0x7beb3af7
Explanation: When a pattern is shifted, each bit shifted off the end is simply lost. In rotation, however, the end bits are treated as if they are connected. That is, when a pattern is right-rotated, the LSB (least significant bit) is placed into the MSB (most significant bit) rather than being lost, as would be the case with a right shift:
0 or 1 -
Right Shift
Right Rotate
Conversely, when a pattern is left-rotated, the MSB is placed into the LSB rather than being lost, as would be the case with a left shift:
MSB
...
S
Left Shift
Left Rotate