Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I convert Decimal Number to a Hexadecimal number in Visual Fox

Status
Not open for further replies.

rr3news

Programmer
Apr 15, 2003
15
0
0
BR
How can I convert Decimal Number to a Hexadecimal number in Visual Fox 7 ??
 

rr3news

How can I convert Decimal Number to a Hexadecimal number in Visual Fox 7 ??

Try Transform:

? TRANSFORM(123,"@0")

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
If you are after a very specific format, such as a four hexdigit group from an integer, you could use:

Code:
FUNCTION DECTOHEX
	PARAMETER m.INTVALUE
	PRIVATE m.STRING,I,X
	DECLARE MBLOCKS[4]
	M.STRING = ""
	FOR I = 4 TO 1 STEP -1
		MBLOCKS[I] = INT(m.INTVALUE/(16 ^ (I-1)))
		M.INTVALUE = m.INTVALUE - (MBLOCKS[I]*(16 ^ (I-1)))
		M.STRING = m.STRING + SUBSTR("0123456789ABCDEF",MBLOCKS[I]+1,1)
	NEXT
	RETURN(m.STRING)

It's a bit clumsy, but it works!



Regards

Griff
Keep [Smile]ing
 
Griff,

At first glance, I, well I got confused.
Is this what you are trying to do?

? Right(TRANSFORM(123,"@0x"), 4) &&... 007B low
? Substr(TRANSFORM(123,"@0x"), 3, 4) &&... 0000 high


Dave S.
[cheers]
 
Dave,

I don't know why I didn't just use the transform thing to be honest - but I overlooked it when I coded my own silly DecToHex function! Then once I had started trying to solve the thing, it became one of those challenges - you know like the ones you did at school just for fun!

I didn't want all the leading bits, just a basic 4 character hex number from an appropriate decimal!

Your approach works just as well, and is probably much faster.

Many thanks

Regards

Griff
Keep [Smile]ing
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top