Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
BitAnd() limitation?
Message
De
07/08/2004 05:54:51
 
 
À
06/08/2004 16:36:07
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00931430
Message ID:
00931526
Vues:
18

hello everybody.

it seems, in Vfp6 Service Pack 5, that the following works:

?bitand(2^30, 2^30) = 2^30 && shows .t.

but the next one does not

?bitand(2^31, 2^31) = 2^31 && shows .f.

is this the limitation of BitAnd()?


No.
BITAND use only INTEGER32 values, then 2^31 set the bit 31 and the value is negative.
?bitand(2^31, 2^31) = - 2^31      && shows .T.
?BITTEST(bitand(2^31, 2^31),31)   && shows .T.

if so, is there a workaround? currently i need to be able to check for values up to 2^33

thanks for all your help in advance!


For bits 0..53 the solution is simple
? BITAND(2^33,2^33) && return 0 because BITAND() use a implicit 0xFFFFFFFF mask
* SOLUTION
CLEAR
x=INT(2^53+2^51+2^49+2^33+2^25)
FOR K=0 TO 53
	IF IIF(m.k<32,BITTEST(m.x,m.K),BITTEST(m.x*2^-31,m.K-31))
		? M.K
	ENDIF
NEXT
Over you have to use a string

Not tested fully:
CLEAR

#DEFINE BITRANGE     1023
#DEFINE BITVARLENGHT 1+BITRANGE/8

x=_BITSET(REPLICATE(CHR(0),BITVARLENGHT),356)

_BITDISPLAY(x)

y=_BITSET(REPLICATE(CHR(0),BITVARLENGHT),100)

_BITDISPLAY(y)

zz=_BITOR(m.x,m.y,_BITSET(REPLICATE(CHR(0),BITVARLENGHT),277))

_BITDISPLAY(ZZ)

PROCEDURE _BITSET(v,iBit)
	RETURN STUFF(m.v,1+m.iBit/8,1,CHR(BITSET(ASC(SUBSTR(m.v,1+m.iBit/8,1)),m.iBit%8)))

PROCEDURE _BITTEST(v,iBit)
	RETURN BITTEST(ASC(SUBSTR(m.v,1+m.iBit/8,1)),m.iBit%8)

PROCEDURE _BITOR(v1,v2,v3,v4,v5,v6,v7,v8,v9)
 PRIVATE v,i,z,k
 v=m.v1
 FOR m.i=2 TO PARAMETERS()  && a long DO CASE is faster
    z=EVAL('m.v'+LTRIM(STR(m.i)))
    FOR k=1 TO BITVARLENGHT STEP 4
    	v=STUFF(m.v,m.k,4,BINTOC(BITOR(CTOBIN(SUBSTR(m.v,m.k,4))-0x80000000,CTOBIN(SUBSTR(m.z,m.k,4))-0x80000000)-0x80000000))
    NEXT
 NEXT
 RETURN m.v
 
PROCEDURE _BITDISPLAY(a)
?
 FOR K=0 TO BITRANGE
	 IF _BITTEST(M.a,M.K)
		?? TRANSFORM(m.K,"@R <9999>")
	 ENDIF
 NEXT
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform