I am not quite sure about this code.
I seem to have some problem understanding what the result should look like.
If I input a base-10 number like
that should yield a binary number
in hex that would be 0000 0100 0000 0000 Right?
The largest base-10 to binary number would be
less than 100000
So how come my answer is showing after a shift a number bigger than 100000???
Forgive my stupidity. This is by far the hardest thing I have tried to imagine, since my brain is used to base-10 format of numbers. Been a very long time that I talked in binary.
here's what I got now:
unsigned int rotate_left(unsigned int i, int n);
printf ("Enter integers and a value to shift them to "
"the left by (separaated by single space): ");
printf("Your original number was %d\n"
"And it was shifted %d places to the left\n",
printf("\nNow results in the number %d \n\n",i);
unsigned int rotate_left(unsigned int i, int n)
for (mask = 0x8000; mask != 0; mask >>=1)
if (mask & i) printf ("1");
else printf ("0");
return ( (i << n) | (i >> ((sizeof(int)*8)-n)) );