Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I\'m trying to write a code in C that repeatedly asks for a 32-bit hex integer.

ID: 672750 • Letter: I

Question

 I'm trying to write a code in C that repeatedly asks for a 32-bit hex integer. If the integer is not 0 it is separated into the 16 highest bits and the 16 lowest bits The highest are rolled to to the left 16 time and the lowest to the right 16 times after each roll the number is reconstituted and printed. I'm trying to figure out how to write the while loop. I know it needs to have two loops.

My code:

void rollHighBitsLeft_rollLowBitsRight ()
{
unsigned int uChoice;
unsigned int halfBitsOfWord = NUM_BITS_PER_WORD / TWO;
unsigned int loMask = (BYTE_WITH_ALL_BITS_ON << ZERO) |
(BYTE_WITH_ALL_BITS_ON << NUM_BITS_PER_BYTE);
unsigned int hiMask = loMask << halfBitsOfWord;
unsigned int maskForRollLeft = ONE << (halfBitsOfWord - ONE);
unsigned int maskForRollRight= ONE;

while ( (uChoice = getHexadecimalInt()) != ZERO )
{

// loops here

}
}

Explanation / Answer

void rollHighBitsLeft_rollLowBitsRight ()
{
unsigned int uChoice;
unsigned int halfBitsOfWord = NUM_BITS_PER_WORD / TWO;
unsigned int loMask = (BYTE_WITH_ALL_BITS_ON << ZERO) | (BYTE_WITH_ALL_BITS_ON << NUM_BITS_PER_BYTE);
unsigned int hiMask = loMask << halfBitsOfWord;
unsigned int maskForRollLeft = ONE << (halfBitsOfWord - ONE);
unsigned int maskForRollRight= ONE;
while ( (uChoice = getHexadecimalInt()) != ZERO )
{
   while(uChoice != ZERO){
       int right16bits = uChoice & loMask;
       int left16bits = uChoice & hiMask;
       right16bits >>= maskForRollRight;
       left16bits <<= ONE;
       uChoice = left16bits + right16bits;
       cout << uChoice << endl;
   }
}
}