I get the right answer. I'm not sure what you're doing wrong...
Code:
itsme@itsme:~/C$ ./shift
10000111 - 87
00001110 - 0E
itsme@itsme:~/C$ cat shift.c
#include <stdio.h>
void show_it(int num)
{
int i;
for(i = 7;i >= 0;--i)
printf("%c", (num >> i) & 1 ? '1' : '0');
printf(" - %02X\n", num);
}
int main(void)
{
unsigned char num = 0x87;
show_it(num);
num <<= 1;
show_it(num);
return 0;
}
Code:
itsme@itsme:~/C$ ./shift
10000111 - 87
00001110 - 0E
itsme@itsme:~/C$
how do i set the LSB to zero? was thinking of an AND mask with 0xFE but would that work?
Yes, but you shouldn't need it. I don't see how that 1 is slipping in.