Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Convert hexa to decimal
Message
From
12/06/2008 09:58:19
 
 
To
12/06/2008 07:19:05
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01323395
Message ID:
01323455
Views:
18
>Hi,
>I want to convert hexa 0x84028A8918BE04 into varchar datatype "37157490954649092",
>evaluate("0x84028A8918BE04") returns 37157490954649090 (precision more than 16 digits),
>can it be done in vfp another way?
>Pavel Poul
__


The conversion is a tricky process
function do_it()
	
	s = '84028A8918BE04'
	
	? LongHexToCurrency(m.s)
         &&   37157490954649092         
endfunc
*---------------------------------------------------------------------------
function LongHexToCurrency(s)

	local d, out, n
	
	&& (1) Pad to 16
	s = padl(m.s, 16, '0')
	
	&& (2) To Hex
	s = strconv(m.s, 16)
	
	&& (3) Reverse the string
	s = StringReverseX(m.s)
	
	&& (4) put string in location of double
	d = 0.00
	=MemoryCopyStringToDouble(@m.d, @m.s, 8)
	
	&& (5) string representation of s
	local out, n
	out = space(32)
	n = sprintfDouble(@m.out, '%I64d', m.d)
	
	return left(m.out, m.n)

	
endfunc
*---------------------------------------------------------------------------
function StringReverseX(s)

  return strconv(StringReverseW(strconv(m.s, 15) + bintoc(0, '2s')), 16)

endfunc
*--------------------------------------------------------------------------
function StringReverseW(s) && wide char

  declare string  _wcsrev in msvcrt.dll as StringReverseW string

  return StringReverseW(m.s)
endfunc
*--------------------------------------------------------------------------
function MemoryCopyStringToDouble(dest, src, siz)
	
	declare	RtlMoveMemory in win32api as MemoryCopyStringToDouble ;
		double  @Dest, string @Src, long BytesToCopy
		
		
	=MemoryCopyStringToDouble(@m.dest, @m.src, m.siz)
endfunc
*--------------------------------------------------------------------------
function sprintfDouble(out, sFormat, in)
	
	declare integer sprintf in msvcrt.dll as sprintfDouble ;
		string@, string@, double 
	
	return sprintfDouble(@m.out, @m.sFormat, m.In)
	
endfunc
*--------------------------------------------------------------------------
Gregory
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform