14-bit left-aligned by two

I have two bytes containing a 14-bit left-justified two extra values and I need to convert it to a short short value (-8192 to +8191, I guess?)

What would be the fastest way to do this?

+3


source to share


2 answers


Just divide by 4.



(Note that right offset leads to implementation / undefined.)

+4


source


Portable solution:



short convert(unsigned char hi, unsigned char lo)
{
  int s = (hi << 6) | (lo >> 2);
  if (s >= 8192)
    s -= 16384;
  return s;
}

      

+1


source







All Articles