Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
VFP Bitwise Functions. ---PLEASE HELP!
Message
 
 
To
14/10/2001 12:26:32
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00567866
Message ID:
00568297
Views:
17
>Hi Sergey,
>
>Thanks for the shiftlbit16 function. I have so little understanding of bitwise functions. I notice in this VO code that there the programmer used Bitwise Shift-Right, BitAnd, and Exclusive OR. Will I need to write/obtain corresponding 16-bit functions for those three functions as well, since he's using short-int Vars? If so do you have any that are public domain or can you direct me to them? Thanks. -Jeff

Hi Jeff,

I don't have a library of 16 bit bitwise finctions. The Bitlshift16 function was wtitten just for your case. I would recomend that you find some C or Assembly beginers books and read a few first chapters to uderstand bitwise operations. Otherwise it's likely that you would miss something in the process of this conversion.
Now, there're the rest of functions you were asking for. Remember that I just wrote them and didn't thoroughly tested.
FUNCTION  BitRshift16
LPARAMETERS tnNumber, tnShift
LOCAL lnRetNumber
* Clear anyting beyond lower 16 bit
lnRetNumber = Bitand( tnNumber, 0xFFFF)
* Perform right shift
lnRetNumber = BitRshift(lnRetNumber, tnShift)
* Check leftmost bit (sign) 
IF Bittest(lnRetNumber,15)
    * it's 16 bit negative number 
    lnRetNumber = -(2^16) + lnRetNumber
ENDIF
RETURN lnRetNumber
*--------------------------------------------------------------
FUNCTION  BitAnd16
LPARAMETERS tnNumber1, tnNumber2
LOCAL lnRetNumber
* Clear anyting beyond lower 16 bit and do bitwise AND
lnRetNumber = Bitand( ;
	Bitand( tnNumber1, 0xFFFF), Bitand( tnNumber2, 0xFFFF))
* Check leftmost bit (sign) 
IF Bittest(lnRetNumber,15)
    * it's 16 bit negative number 
    lnRetNumber = -(2^16) + lnRetNumber
ENDIF
RETURN lnRetNumber
*-------------------------------------------------------------
FUNCTION  BitXor16
LPARAMETERS tnNumber1, tnNumber2
LOCAL lnRetNumber
* Clear anyting beyond lower 16 bit and do bitwise XOR
lnRetNumber = BitXor( ;
	Bitand( tnNumber1, 0xFFFF), Bitand( tnNumber2, 0xFFFF))
* Check leftmost bit (sign) 
IF Bittest(lnRetNumber,15)
    * it's 16 bit negative number 
    lnRetNumber = -(2^16) + lnRetNumber
ENDIF
RETURN lnRetNumber
As you can see there's a pattern in the code:
1. Clear anyting beyond lower 16 bit in the passed numbers
2. Perform VFP bitwise operation
3. Check if the result is a negative 16 bit number and convert accordingly.

Be advised that a result returned by all those functions internally still 32-bit long number because that's the way VFP stores integers.
--sb--
Previous
Reply
Map
View

Click here to load this message in the networking platform