Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
BITLSHIFT
Message
De
22/11/1999 18:01:41
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
Divers
Thread ID:
00293960
Message ID:
00294113
Vues:
23
>>>>I am trying to use the bitlshift command to shift bits from a hexidecimal representation.
>>>>
>>>>The following gives me what I expect
>>>>
>>>>hexval = 0x00F00000
>>>>newhexval = bitlshift(hexval,4)
>>>>newhexval = transform(newhexval,"@0")
>>>>
>>>>now newhexval = 0x0F000000
>>>>
>>>>however this does not work
>>>>
>>>>hexval = 0x0F000000
>>>>newhexval = bitlshift(hexval,4)
>>>>newhexval = transform(newhexval,"@0")
>>>>
>>>>I expected newhexval to be 0xF0000000 but it ends up being a negative number. Is there something I am missing or not understanding?
>>>>
>>>>Thanks.
>>>Hi David,
>>>
>>>There's nothing you're missing. What's happened is that the most significant bit represents the sign. When it's set as would be the case with any hex value of 0x80000000 up, VFP will interpret it as negative.
>>
>>Thanks for the reply George. What I don't understand is why
>>
>>evaluate("0xF0000000")
>>
>>returns 4026531840 which is a positive number and
>>
>>transform(4026531840,"@0")
>>
>>returns "0xF0000000".
>
>This has to do with the way that signed integers are represented.
>Eg. 0xFFFFFFFF is -1.
>

Is there a way to make Foxpro show always the signed value or always the unsigned value?

>If you directly print this value in VFP, it will show the non-signed integer value.
> ? 0xFFFFFFFF
> display: 4294967295
>
>But, if you use some of the bit manipulation functions (bitand, bitor, bitlshift, etc.), VFP will show the signed integer value.
> ? bitor(0xFFFFFFFF, 0)
> display: -1
>
>To convert a negative value to its correspondent non-signed value:
>
>
>newhexval = bitlshift(hexval,4)
>If newhexval < 0
>    newhexval = 0xFFFFFFFF + newhexval + 1
>Endif
>newhexval = transform(newhexval,"@0")
>
>
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform