I am shifting the bits of a BCD number either left or right to quickly multiply or divide by 2. Here is a quick example of shifting left:
void LShift(unsigned char *arg)
{
int i, carry=0, temp;
for(i=2;i>=0;i--)
{
temp=(arg[i]<<1)+carry;
if (temp>9) temp+=6;
carry=temp>>4;
arg[i]=temp&0xF;
}
}
This works fine and if you give it an array like {4,5,6}
it will return {9,1,2}.
The problem is that if I want to shift by more than one bit, I have to call the function over and over. Is there any clever way to shift by more than one bit at a time without converting the BCD number to decimal first?