I' m trying to solve a problem:
The program should read a positive integer and a number for the octades (n).
The program should show the outcome of the value by rotating the given number by n octades to the right. We have to suppose that the length for integers is 32 bits and that the user enters for the number of octades a value of 1-3. For example, if the user enters 553799974 (bin: 00100001|00000010|01010001|00100110) the program should display: 639697489 (bin: 00100110|00100001|00000010|010 10001).
I wrote this code for the case of 1 octade:
Code:
#include <stdio.h>
int main()
{
unsigned int num;
unsigned int temp;
int n;
//printf("Enter number: ");
//scanf("%d",&num);
num = 553799974;
//printf("Enter oct: ");
//scanf("%d",&n);
n=1;
if (n == 1){
printf("Num is: %d\nand Temp is: %d\n\n",num, 0xFF);
temp = num & 0xFF; //00000000000000000000000011111111 (under the 32-bit integer).
temp <<= 8;
temp += num >> 8;
}
printf("Now\n\nNum is: %d\nand Temp is: %d",num, temp);
return 0;
}
Where is my mistake? It returns 2173009 back and not the 639697489