>Hi Larry,
>
>Thanks for your reply. I was excited when I saw your simple solution. However, I'm still not getting the values that I need in every situation.
>Consider the following:
>
>lcTest = -32768
>lcTest = bitlshift(lcTest,1) && lcTest now equals -65534 (which doesn't work)
>lctest = -(2^16) + lcTest && lcTest now equals -131070, which as you said doesn't work either for the range of a shortint.
>
>The VO function that does a bitLeftShift when lcTest = -32768, returns a 0 (zero)
>
>These bitwise functions make me feel like an idiot as I just don't understand them... Unfortunately, I can't have the programmer change to a longint. What should I do in the instance above? -Jeff
Jeff,
Sorry I couldn't be of more help. Here is some information to help understand what's going on.
In bit notation, numbers are represented in binary form. Ex.
1 = 1 = 2^0
2 = 10 = 1*(2^1) + 0*(2^0)
3 = 11 = 1*(2^1) + 1*(2^0)
4 = 100 = 1*(2^2) + 0*(2^1) + 0*(2^0)
When you apply the BitLShift(,1) function to a number, it shifts all values 1 place to the left and appends a 0 to the end of the number. So BitLShift(4,1) yields
1000 = 1*(2^3) + 0*(2^2) + 0*(2^1) + 0*(2^0)
The problem you are running into is VFP does not limit you with respect to data types. Numeric values are in reality doubles with a limit of about +/- 2^1022. BitLShift() appears to have a limit of +/- 2^30 before it returns a 0 like the function in VO (limitation of a long data type).
Without having VO and knowing exactly how it handles values outside of the specified range, I don't think I could come up with an algorithm to fit all values. Maybe someone more fluent in C++ could jump in with a way around this.
HTH.
Larry Miller
MCSD
LWMiller3@verizon.netAccumulate learning by study, understand what you learn by questioning. -- Mingjiao