Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Convert to hex ??
Message
De
22/07/2008 10:13:51
 
 
À
22/07/2008 06:53:43
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 8 SP1
Divers
Thread ID:
01332438
Message ID:
01333145
Vues:
13
>>>Your suggestion works very well with positive number (90% of database) but negative numbers don't show the right result.
>>>eg : -77442022681 should show up as EDF81882E7. Your help will be appreciated. TIA
>>
>>From the wiki link I gave you in a previous post, modified to work with negative numbers, the way you want it:
>>
>>
>>
>>?basex(249272136572 , "0123456789abcdef")
>>?basex(-77442022681, "0123456789abcdef")
>>
>>Function BaseX( txVal, tcDom )
>>	* Converts a number to a string representation of that number
>>	* tnVal - Number
>>	* tcDom - The domain of characters to be used
>>	* typical Domains are:
>>	* "01" - Binary
>>	* "0123456789" - Decimal
>>	* "0123456789abcdef" - Hex
>>	* "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" - Base62
>>	* "23456789ABCDEFGHJKLMNPRSTUVWXYZ" - No {01IOQ} - they might confuse a user.
>>
>>	* If you want the result padded, use PADL()
>>
>>	Local ;
>>		lnVal, ;
>>		lnDomSiz, ;
>>		lcRet, ;
>>		lnPosition, ;
>>		lnPlace
>>
>>	If Vartype(txVal) = "N"
>>		If txVal < 0 Then
>>			txVal = txVal + 1
>>		Endif
>>		lnVal = txVal
>>		lnDomSiz = Len(tcDom)
>>
>>		* Humans get restless if the value zero is displayed as an empty string (blank).
>>		* The first char of the domain (generally 0) is normally used as a place holder,
>>		* but in the case of the value zero, it fills in to keep the peace.
>>		* This may have lead to the fall of Rome.
>>
>>		If lnVal = 0
>>			lcRet = Substr( tcDom, 1, 1 )
>>		Else
>>			lcRet = ''
>>			Do While lnVal <> 0
>>				lnDig = lnVal % lnDomSiz
>>				lnVal = Int( lnVal/lnDomSiz )
>>				If txVal > 0 Then
>>					lcDig = Substr( tcDom, lnDig+1, 1 )
>>				Else
>>					If lnDig = 0 Then
>>						lnDig = 16
>>					Endif
>>					lcDig = Substr( tcDom, lnDig, 1 )
>>				Endif
>>
>>				lcRet = lcDig + lcRet
>>			Enddo
>>		Endif
>>		lxRet=lcRet
>>	Else
>>		* Convert it back to decimal
>>		lnVal = 0
>>		lnPlace = 0
>>		For lnPosition = Len(txVal) To 1 Step -1
>>			lnVal = lnVal + (At( Substr(txVal,lnPosition,1), tcDom)-1) * (Len(tcDom)^lnPlace)
>>			lnPlace=lnPlace+1
>>		Endfor
>>		lxRet = lnVal
>>	Endif
>>
>>	Return lxRet
>>Endfunc
>>
>>
>>Carlos Alloatti
>
>Hi Carlos,
>This code wouldn't correctly convert the number Shafid requested, no?
>Cetin

Hi Cetin, I modified the original code taken from the vfp wiki, so it works with negative numbers and works as he wanted.

I really don´t know for shure if -77442022681 should be EDF81882E7, that is not what the Windows Calculator says.

Carlos
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform