Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Looking for numeric/hex converter
Message
De
25/08/1998 12:32:02
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00129745
Message ID:
00129750
Vues:
24
>Hi gang...
>
>I'm looking for a snippet/module that converts a numeric value to a hexadecimal value, and vice versa if possible.
>
>Prefer Fox26, but VFP will do.
>
>If there's one in existence in the files section, could somebody point me in the right direction? If not, has anyone written such an animal and can tell me what the "gotchas" are?
>
>TIA,
>
>Evan Pauley
Evan,
Check vfp5\tools\hexeditor.scx. And here are some basic routines for conversion :
function dec2hexb
lparameters nDecimal, nDigits
if parameters() < 2
	nDigits = 1
endif	
if nDecimal > 0xffffffff		&& Greater than 32 bit value
	highdword = int(nDecimal / 0x0ffffffff)
	lowdword = 	bitand(nDecimal,0x0ffffffff)
	return dec2hexb(highdword,8)+dec2hexb(lowdword,8)
endif	
cHexString = ""
do while nDecimal > 0
	cHexString = ;
		dec2HexDigit(bitand(nDecimal,0x0F)) ;
		+ cHexString							&& Constitute righmost digit
	nDecimal = bitrshift(nDecimal,4)			&& Drop rightmost digit
enddo
return padl(cHexString,max(nDigits,len(cHexString)),"0")

function Dec2HexDigit
lparameters nDigit
return iif(nDigit > 9, ;
	chr(asc("A")+nDigit-10),;
	chr(asc("0")+nDigit))

function hex2dec
lparameters tcHexBytes
return eval("0x"+tcHexBytes)
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform