Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
VFP Bitwise Functions. ---PLEASE HELP!
Message
From
12/10/2001 17:33:56
 
 
To
12/10/2001 16:55:56
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00567866
Message ID:
00568002
Views:
24
>Again... I feel like an idiot.... Your explanation was way over my head. I'm not sure how to apply your suggestions in the original example I gave. Larry suggested that I do the following if the value is greater than 32767
>
>-(2^16) + lcTest
>
>How would you change that? -Jeff
>p.s. sorry to be a pest.

No prob...

This is off the top of my head. It is probably off in it's return values, but it may give you something to work with
FUNCTION  MyShiftLeft
LPARAMETER           tnValue, tnPositions
LOCAL                lnReturn

    lnReturn = bitlshift (tnValue, tnPositions)
    IF lnReturn >= 32768
        lnIntegerBits = BITAND (lnReturn, 65535)     &&  Strip off BigInt bits beyond integer boundary.
        IF lnIntegerBits = 32768
            lnSignedIntegerValue = -32768
        ELSE
             lnSignedIntegerValue = - (lnIntegerBits - 32768) 
        ENDIF
        lnReturn = lnSignedIntegerValue
    ENDIF

    RETURN   lnReturn
ENDFUNC
Why the pattern you noticed?

VFP follows the powers of 2 from 2^14 to 2^15 (which is what your shift lefts are doing at the 15th and 16th digits from the right). Note the following values

16384 = 010000000000000 = 2^14
32768 = 100000000000000 = 2^15

But, a signed value reserves the most significant bit (in the Intel architecture) for the sign. O = positive, 1 = negative.

So, in a signed byte value, the 16th bit is the sign. This is the result.
-32768 = 100000000000000
Why? because you don't need a negative 0, which is what, according to the rule, the value should be.

Otherwise, signed byte values go like positives except with the leading sign bit:
-1 = 1000000000000001
-32767 = 1111111111111111

I'm not sure if that helps, but that's what's going on under the hood.

Let Larry and I know your progress, if you don't mind.


Jay
Previous
Reply
Map
View

Click here to load this message in the networking platform