hello Fabio
Sorry it took me so long to get back to you.
i have tryed to modify your first example for my needs, but i can not get it to work. here is what i have:
* *** the following returns .t. (correct)
?Test(;
2^2 + ;
2^2 + ;
2^3 + ;
2^4 + ;
2^5 + ;
2^6 + ;
2^7 + ;
2^8 + ;
2^9 + ;
2^10 + ;
2^11 + ;
2^12 + ;
2^13 + ;
2^14 + ;
2^15 + ;
2^16 + ;
2^17 + ;
2^18 + ;
2^19 + ;
2^20 + ;
2^21 + ;
2^22 + ;
2^23 + ;
2^24 + ;
2^25 + ;
2^26 + ;
2^27 + ;
2^28 + ;
2^29 + ;
2^33, ;
2^33)
* *** the following returns .f. (incorrect)
?Test(;
2^2 + ;
2^2 + ;
2^3 + ;
2^4 + ;
2^5 + ;
2^6 + ;
2^7 + ;
2^8 + ;
2^9 + ;
2^10 + ;
2^11 + ;
2^12 + ;
2^13 + ;
2^14 + ;
2^15 + ;
2^16 + ;
2^17 + ;
2^18 + ;
2^19 + ;
2^20 + ;
2^21 + ;
2^22 + ;
2^23 + ;
2^24 + ;
2^25 + ;
2^26 + ;
2^27 + ;
2^28 + ;
2^29 + ;
2^30 + ;
2^31 + ;
2^32 + ;
2^33, ;
2^33)
Func Test
LPARA ;
MasterBit, ;
TestBit
LOCAL ;
ReturnValue
* *** this only works from 0 to 53 (like 2^53)
IF IIF(;
LOG(TestBit) / LOG(2) < 32, ;
BITTEST(MasterBit, LOG(TestBit) / LOG(2)), ;
BITTEST(MasterBit*2^-31, (LOG(TestBit) / LOG(2))-31))
ReturnValue = .T.
ELSE
ReturnValue = .F.
ENDIF
RETURN(ReturnValue)
this still will not let me test correctly for large numbers. do you see what i am doing wrong here?
Thanks for your help.
Because you write a bad number :
....
2^2 + ;
2^2 + ;
....
This generate a carry bit that change the number's bits pattern.
Use the next, it is more faster,simple and sure:
clear
?Test(;
2^1 + ;
2^2 + ;
2^3 + ;
2^4 + ;
2^5 + ;
2^6 + ;
2^7 + ;
2^8 + ;
2^9 + ;
2^10 + ;
2^11 + ;
2^12 + ;
2^13 + ;
2^14 + ;
2^15 + ;
2^16 + ;
2^17 + ;
2^18 + ;
2^19 + ;
2^20 + ;
2^21 + ;
2^22 + ;
2^23 + ;
2^24 + ;
2^25 + ;
2^26 + ;
2^27 + ;
2^28 + ;
2^29 + ;
2^33, ;
2)
?Test(;
2^1 + ;
2^2 + ;
2^3 + ;
2^4 + ;
2^5 + ;
2^6 + ;
2^7 + ;
2^8 + ;
2^9 + ;
2^10 + ;
2^11 + ;
2^12 + ;
2^13 + ;
2^14 + ;
2^15 + ;
2^16 + ;
2^17 + ;
2^18 + ;
2^19 + ;
2^20 + ;
2^21 + ;
2^22 + ;
2^23 + ;
2^24 + ;
2^25 + ;
2^26 + ;
2^27 + ;
2^28 + ;
2^29 + ;
2^30 + ;
2^31 + ;
2^32 + ;
2^33, ;
31)
FUNCTION Test
LPARA MasterBit, TestBit
RETURN BITTEST(m.MasterBit*2^MIN(0,32*SIGN(31-m.TestBit)), m.TestBit%32)