Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Bitand on more than 32 bits
Message
De
12/02/2003 17:21:09
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00751377
Message ID:
00752523
Vues:
26
>Hi,
>
>How can I make a bitand() on more than a 32 bits numeric expression ?
>
>Thanks

You can't do a bitwise operation directy for numeric bigger than 32 bits, cause it is the limitation for the current machine (except for the latest 64 bit machine). One of the workaround for this is to make 2 of 32 bits (DWORD) numeric. One represent as HI-DWORD and the other one represent as LO-DWORD. Combine the result to get a 64 bits numeric.

I have a workaround sample for bit shifting. Adjust it to what you need.
Try the code below in your command window with:
?Hex64(0x00000008, 0x00000000 , 0, 1)
?Hex64(0x00000008, 0x00000000 , 1, 1)
?Hex64(0x00000008, 0x00000000 , 2, 1)
?Int64(0x00000008, 0x00000000 , 1, 1)
?Int64(0x00000008, 0x00000000 , 2, 1)
Function Int64(tn_HighVal, tn_LowVal, tn_BitCount, tn_Mode)
   Return val(Hex64(tn_HighVal, tn_LowVal, tn_BitCount, tn_Mode))
EndFunc

Function Hex64(tn_HighVal, tn_LowVal, tn_BitCount, tn_Mode)
Local i, ln_HighVal, ln_LowVal
Local lc_HighHex, lc_LowHex

   ln_LowVal = tn_LowVal
   ln_HighVal = tn_HighVal
   Do case
      Case (tn_Mode = 1)	&& Shift right
         For i = 1 to tn_BitCount
            ln_LowVal = BitRShift(ln_LowVal, 1)
            If (BitAnd(ln_HighVal,1) == 1)
               ln_LowVal = BitOr(ln_LowVal, 0x80000000)
            endif
            ln_HighVal = BitRShift(ln_HighVal,1)
         Next

      Case (tn_Mode = 2)	&& Shift left
         For i = 1 to tn_BitCount
            ln_HighVal = BitLShift(ln_HighVal,1)
            If (BitAnd(tn_LowVal, 0x80000000) == 1)
               ln_HighVal = BitOr(ln_HighVal, 1)
            endif
            ln_LowVal = BitLShift(ln_LowVal, 1)
         Next
   EndCase
   lc_HighHex = substr(transform(ln_HighVal, '@0'), 3)
   lc_LowHex = substr(transform(ln_LowVal, '@0'), 3)
   Return '0x' + lc_HighHex + lc_LowHex
EndFunc
HTH
Herman
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform