Question

In: Computer Science

Rotating bits in C This rotates bits to the left which means the bits that were...

Rotating bits in C

This rotates bits to the left which means the bits that were shifted off are then moved to the right side.

I need B5DE1FAA to become 7787EAAD

uiOrig = B5DE1FAA

k = 6

unsigned int rotateLeft(unsigned int uiOrig, int k){

}

Solutions

Expert Solution

SOURCE CODE:

*Please follow the comments to better understand the code.

**Please look at the Screenshot below and use this code to copy-paste.

***The code in the below screenshot is neatly indented for better understanding.

#include <stdio.h>
unsigned int rotateLeft(unsigned int uiOrig, int k)
{
// left shift the bits k times.
unsigned int shiftedResult= (uiOrig<<k);
  
// now take the last k bits from original number and move it to front using
// right shift >> operator and | or operator
// here 8 is the number of bits in a byte.
shiftedResult |= uiOrig >> (sizeof(uiOrig)*8 - k);
  
// return the obtained result
return shiftedResult;

}

int main()
{
// test the method
unsigned int uiOrig=0xB5DE1FAA;
int k=6;
unsigned int shiftedResult=rotateLeft(uiOrig,k);
printf("The Result is: %X",shiftedResult);
return 0;
}

==========

SCREENSHOT:


Related Solutions

1) Explain the oprerating principle of left-rotating, right rotating shift register by sketching the circuit and...
1) Explain the oprerating principle of left-rotating, right rotating shift register by sketching the circuit and timing diagram for 4-bit register configurations?
Add 011 0011 to 010 1100 and show the V and C bits (seven bits and...
Add 011 0011 to 010 1100 and show the V and C bits (seven bits and show work)
Add 111 0011 to 100 1100 and show the V and C bits (seven bits)
Add 111 0011 to 100 1100 and show the V and C bits (seven bits)
Jack wants to build a circuit to shift 4 bits (I0 to I3 from left to...
Jack wants to build a circuit to shift 4 bits (I0 to I3 from left to right) in a circular way. One extra bit (S) is used to control the direction of shifting. When S = 0, the bits should be shifted left, otherwise right. The outputs are O0 to O3 from left to right. For example, when shifted right, 0011 would become 1001; when shifted left, 0011 would become 0110. Please help Jack get started by providing the fourth...
Using C (not C++): setFirst - returns value with n upper bits set to 1 and...
Using C (not C++): setFirst - returns value with n upper bits set to 1 and 32-n lower bits set to 0 * You may assume 0 <= n <= 32 * Example: setFirst(4) = 0xF0000000 * Legal ops: ! ~ & ^ | + << >> (NO IF OR FOR LOOPS) * Max ops: 10 * Rating: 2
Write instruction(s) in C to get bits 4 and 7 of Port-C, then compute the “XOR...
Write instruction(s) in C to get bits 4 and 7 of Port-C, then compute the “XOR (exclusive OR)” of these two bits and write the result of the “XOR operation” to bit 4 of Port-D.
Write instruction(s) in C to get bits 4 and 7 of Port-C, then compute the “XOR...
Write instruction(s) in C to get bits 4 and 7 of Port-C, then compute the “XOR (exclusive OR)” of these two bits and write the result of the “XOR operation” to bit 4 of Port-D.
1- Write it with C++ program §Write a function Rotate that rotates an array of size...
1- Write it with C++ program §Write a function Rotate that rotates an array of size n by d elements to the left §Use array as argument §In the main function, call the function Rotate and show the rotated array §Test your code For example: Input: [1 2 3 4 5 6 7], n = 7, d = 2 Output: [3 4 5 6 7 1 2] 2- Write it in C++ §Search Insert Position •Given a sorted array in...
By two years of operation, Big Fish Company’s inventory costs were rising. which means LIFO or...
By two years of operation, Big Fish Company’s inventory costs were rising. which means LIFO or FIFO gives the lowest ending inventory valuation on the balance sheet and which method gives the lowest net income? A: Net Income: LIFO; Ending Inventory: FIFO B: NI: FIFO; EI: LIFO C: EI & NI: FIFO D: EI & NI: LIFO
Identify five situations in which rotating unbalances can occur ?
Identify five situations in which rotating unbalances can occur ?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT