unHex a number

Blitz3D Forums/Blitz3D Programming/unHex a number

Rook Zimbabwe(Posted 2005) [#1]
Lets say I use
number$ = Hex$(199999)
to get a hex value for 199999... How do I unhex that number later if I need to? I have looked in the Command Reference and possibly I missed it.
RZ


EOF(Posted 2005) [#2]
Print hex2dec("c000")
Input
End

Function hex2dec(hexin$)
	Local c, dec, hexval$ = "0123456789ABCDEF"
	For c=1 To Len(hexin$)
	dec = (dec Shl 4) Or (Instr(hexval$, Upper$(Mid$(hexin$, c, 1))) - 1)
	Next
	Return dec
End Function



Rook Zimbabwe(Posted 2005) [#3]
Thankyew.... That is a hairy piece of math there! I appreciate it!

Now when I do this:
ascii$=Hex$(250000)
Print ascii$
Print hex2dec(ascii$)
Input
End

Function hex2dec(hexin$)
	Local c, dec, hexval$ = "0123456789ABCDEF"
	For c=1 To Len(hexin$)
	dec = (dec Shl 4) Or (Instr(hexval$, Upper$(Mid$(hexin$, c, 1))) - 1)
	Next
	Return dec
End Function
I don't see it work... Hmmm... Maybe if I renamed the $ variable to match your variable name...

OK itis 2:46AM here and I apologize... it was working GREAT but my brain sin't... manaņa amigos
RZ


Bremer(Posted 2005) [#4]


This should work for you.


Rook Zimbabwe(Posted 2005) [#5]
works good Zawran... negligible difference in time to execute too... Thanks


Bremer(Posted 2005) [#6]
No problem, glad I could help.


RGR(Posted 2005) [#7]
Function HexToInt(H$)
	integer=0
	For i=1 To Len(h$)
		hdigit=(Asc(Mid$(h$,i,1))-48) And $1f
		If hdigit>9 Then hdigit=hdigit-7
		integer=(integer Shl 4)+hdigit
	Next
	Return integer
End Function



Apocalypse(Posted 2005) [#8]
What a wonderful function to add to my Userlib. Easy to use and very, very FAST!!

http://www.blitzbasic.com/logs/userlog.php?log=440&user=7138