Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
VFP Bitwise Functions. ---PLEASE HELP!
Message
 
 
To
14/10/2001 13:58:39
Dragan Nedeljkovich (Online)
Now officially retired
Zrenjanin, Serbia
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00567866
Message ID:
00568306
Views:
15
Hi Dragan,

< snip >
>You only have to take care of BitLShift(), because BITAND( ),BITCLEAR( ), BITOR( ) , BITSET( ), BITTEST( ) and BITXOR( ) will not produce more bits in the result than there were in the operands.

It would be true if foxpro kept results as 16 bit integers.

Keep in mind that BITNOT( ) will produce a 32-bit complement of your integer, i.e. if in 16 bit arithmetic bitnot(0) will be 0x0000ffff, in 32-bit it will be 0xffffffff. Also, doing Bitor() and BitXor() where one operand may be negative or above 32767, will yield numbers outside of the 16-bit range. The safe thing to do (if you want to keep it 16-bit) is to strip the upper 16 bits:
>
>function bitor16(n1,n2)
>return bitand(bitor(n1,n2), 0x0000ffff)
>
>function bitxor16(n1,n2)
>return bitand(bitxor(n1,n2), 0x0000ffff)


Here's the test
lnNumber = BitLshift16( 1, 15)     && -32768 or 0xFFFF8000
* As you can see it has already more bits that we want
? Bitand(Bitxor( lnNumber, 0), 0xffff)   && returns 32768 instead of -32768
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform