twitter
    Find out what I'm doing, Follow Me :)

The Shift Instructions

The last two operations to be covered in this chapter are the left shift and the right shift instructions. Load the example program shifter.c for an example using these two instructions.

The two operations use the following operators;
<< n Left shift n places.
>> n Right shift n places.


main( )
{
int small,big,index,count;
printf(" shift left shift right\n\n");
small = 1;
big = 0x4000;
for(index = 0;index < 17;index++) {
printf("%8d %8x %8x\n",small,small,big);
small = small << 1;
big = big >> 1;
}
printf("\n");
count = 2;
small = 1;
big = 0x4000;
for(index = 0;index < 9;index++) {
printf("%8d %8x %8x\n",small,small,big);
small = small << count;
big = big >> count;
}
}


Once again the operations are carried out and displayed using the hexadecimal format. The
program should be simple for you to understand on your own, there is no tricky code.