Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
BitAnd() limitation?
Message
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00931430
Message ID:
00931482
Views:
18
I think you can use BitTest instead of BitAnd for this kind of query.
? BitTest(3+16+256, 4) && .T.
? BitTest(3+16+256, 8) && .T.
? BitTest(3+16+256, 7) && .F.
? BitTest(3+16+256, 1) && .T.
? BitTest(3+16+256, 2) && .F.
? BitTest(3+16+256, 0) && .T.
Then, following the idea of BitTest, you can convert the number into a binary string, and make a custom 'BitTest' for strings, something like:
? SBitTest(ToBin(3+16+256), 4) && .T.
? SBitTest(ToBin(3+16+256), 8) && .T.
? SBitTest(ToBin(3+16+256), 7) && .F.
? SBitTest(ToBin(3+16+256), 1) && .T.
? SBitTest(ToBin(3+16+256), 2) && .F.
? SBitTest(ToBin(3+16+256), 0) && .T.
function ToBin(tnNumber)

local lnNumber

if Vartype(tnNumber) # 'N'
	return ''
endif

lcNumber	= Right(Transform(tnNumber, '@0X'), 8)
lcBinNumber	= ''
 
for i = 1 to 8
	lcDigit		= Substr(lcNumber, i, 1)
	lnDigit		= Iif(Isdigit(lcDigit), Val(lcDigit), Asc(lcDigit) - Asc('A') + 10)
	for j = 3 to 0 step -1
		lcBinNumber = lcBinNumber + Iif(Bittest(lnDigit, j), '1', '0')
	next j
next i
return lcBinNumber
function SBitTest(tcNumber, tnDigit)

return Left(right(tcNumber, tnDigit + 1), 1) = '1'
I know this will have an impact on performance and efficiency, but (with some tweaking) it should work for a lot of options! :)

(I wrote all this functions very quickly, so I am not sure they work completely right!)
"The five senses obstruct or deform the apprehension of reality."
Jorge L. Borges?

"Premature optimization is the root of all evil in programming."
Donald Knuth, repeating C. A. R. Hoare

"To die for a religion is easier than to live it absolutely"
Jorge L. Borges
Previous
Reply
Map
View

Click here to load this message in the networking platform