>>
>>Ok, I got it! But why not simply:
>>
>>bitand(lnRight, 0x7f)*256 + lnLeft
>>
>>Vlad
>
>Traditionally, a low level bitshift is Much faster than multiplication by a floating point value. But since this is foxpro, and we are actualling calling functions, the performance gains are probably lost.
I just tested this. Using shifting vs. multiplication is faster with about 3/10000000 seconds.
>The readability is also reduced using my technique whereas in C++ it would be:
>
>unsigned char lcShort[2];
>short x;
>// ...
>x = ((lcShort[1] & 0x7f) << 8) | lcShort[0]);
>x = (lcShort[1] & 0x80) ? (-x) : (x);
>
which would be thousands of times faster than the equivalent FoxPro and tens of times faster than the equivalent C++ using multiplies instead of bit operations.
A good C/C++ compiler should optimize internally code that multiplies by 256 using a right shift, IMHO.
>Of course in C++, the initial reason we had to unpack a short becomes moot :-)
Right. :)
Vlad