Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
VFP Bitwise Functions. ---PLEASE HELP!
Message
From
12/10/2001 16:30:55
 
 
To
12/10/2001 16:03:56
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00567866
Message ID:
00567959
Views:
22
>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 --

I believe the problem you're running into is this.

The data type you're using in VO is a signed integer -- 16 bits, 15 for value, 1 for sign.

The data type that VFP uses, I think, when doing bit calculations is a signed bigint -- 32 bits, 31 for value, 1 for sign.

Two options:
1. When porting the VO code, translate it to VFP #'s.
2. Write your own conversion program in VFP so that VFP gives you the values you need.

Thinking through option 2.

1. You don't have a problem until you get a bit in the most significant bit.
So, if the value is > 0, you're OK.

2a. If the value is negative, then apply an AND 65535 to the resulting value. This will strip off VFP's more significant digits which you don't want. (In AL, the Shift drops off digits which go beyond the beginning or end of the value boundaries, while a Rotate recycles them at the opposite end (through the carry bit)).

2b. It's not clear how VO is representing negative numbers. If the number is negative, I think I'd take VFP's value, subtract -65536 from it, and you may end up with VO's number.

HTH,


Jay




3.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform