Hi guys,
I have a question about a program i'm writing as an assignment for school.
It has to rotate bits and whenever bit fall out on one side the bit has to be send to the other side (i hope it's clear it's also called cyclic i think).
in N = positive the bits need to shift to the left and when N in negative the bits shift to the right. So far this works. The only thing i don't know is how to catch the bits that are falling out and return them to the other side of the bit sequence.
Hope this all is clear
my code:
Code:
#include <stdio.h>
#include <stdlib.h>
unsigned int roteer(unsigned int waarde, int n);
int main(void)
{
int uitkomst = roteer(4,-2);
printf("%d ", uitkomst);
system("pause");
return 0;
}
unsigned int roteer(unsigned int waarde, int n)
{
int getal;
int rechtsCounter;
int counter = 0;
if(n >= 0)
{
getal = waarde << n;
}
else
{
rechtsCounter = n;
while(rechtsCounter < 0)
{
counter++;
rechtsCounter++;
}
rechtsCounter = counter;
getal = waarde >> rechtsCounter;
}
return getal;
}