Problem: Left-rotate a 16-bit number N by B bit positions. Could someone please explain to me how to write out this problem in a Flow Chart. I also need to write this in assembly language. It would be very helpful if you were able to do both or either one. Also, a friend of mine managed to figure out how to left rotate it but for some reason it would drop a 1 after a few complete rotations. For Example: Bit: 1111 0000 1111 0000 Rotated Once: 1110 0001 1110 0000 BUT the result should come out like this: 1110 0001 1110 0001 Could you also please explain what the problem is? Thank You
Explanation / Answer
#include #define INT_BITS 32 /*Function to left rotate n by d bits*/ int leftRotate(int n, unsigned int d) { /* In nd, first d bits are 0. To put last 3 bits of at first, do bitwise or of n>>d with n d)|(n