Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to convert between Decimal and Hexadecimal using VFP
Message
From
17/11/2006 09:25:55
 
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 6 SP5
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01170587
Message ID:
01170683
Views:
7
That's what I get for not paying close enough attention when I type. It looks like George Tasker's basic formula:

TRANSFORM(100, "@0")

works...
>>
>>FUNCTION hexi2deci
>>PARAMETER txhex
>>lndecimal = 0
>>FOR i = LEN(txhex) TO 1 STEP -1
>>   lndecimal = lndecimal + (AT(SUBSTR(txhex, i, 1), ;
>>	"0123456789ABCDEF") - 1) * 16 ^ (LEN(txhex) - i)
>>NEXT
>>RETURN lndecimal
>>
>>
>>FUNCTION deci2hexi
>>PARAMETER tndec
>>RETURN TRANSFORM(ASC(RIGHT(tndec,1))*(256^3)+;
>>	ASC(SUBSTR(tndec,3,1))*(256^2)+;
>>	ASC(SUBSTR(tndec,2,1))*(256)+ASC(LEFT(tndec,1)))
>>
>
>The Hexi2Deci() works, but Deci2Hexi() doesn't. E.g. trying Deci2Hexi("100") produces "808464433".
>
>Another comment: The parameter name suggests that a numerical value is expected as input. However, the routine expects a character type numerical value.
.·*´¨)
.·`TCH
(..·*

010000110101001101101000011000010111001001110000010011110111001001000010011101010111001101110100
"When the debate is lost, slander becomes the tool of the loser." - Socrates
Vita contingit, Vive cum eo. (Life Happens, Live With it.)
"Life is not measured by the number of breaths we take, but by the moments that take our breath away." -- author unknown
"De omnibus dubitandum"
Previous
Reply
Map
View

Click here to load this message in the networking platform