Hello, I want to make a function that shifts bits to the left and right and append them to the left or the right.I heard that is is called ROR and ROLL?
Example (to the left):
#include <stdio.h>
void rolBits(int v)
{
int i;
int mask = 1 << 31;
for(i=1; i<=32; ++i)
{
putchar(((v & mask) == 0) ? '0' : '1');
v <<= 1;
if(i % 8 ==0 &&i <=32)
putchar(' ');
}
}
int main(void)
{
unsignedint v;
unsignedint b;
int a;
unsignedint c = 1 << (b-1) ;
printf("Give a positive integer:\t");
scanf("%d",&v);
printf("Give the amount of positions you want to shift:\t");
scanf("%d",&b);
printf("Wich side do you want to shift to? (L/R)");
scanf("%s",&a);
unsignedint g = (v << b) | (v >> b);
printf("Binary this is:\t\t\t\t");
rolBits(v);
if(a == 'l' || a == 'L')
{
printf("\nThe bit has been shifted to the left:\t\t");
rolBits(g);
}
else
{
printf("Binary this is:\t\t\t");
rolBits(v);
printf("\nThe bit(s) has been shifted to the right\t\t");
rolBits(k);
}
getchar();
getchar();
}