unHex a number
Blitz3D Forums/Blitz3D Programming/unHex a number
| ||
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 |
| ||
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 |
| ||
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 FunctionI 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 |
| ||
This should work for you. |
| ||
works good Zawran... negligible difference in time to execute too... Thanks |
| ||
No problem, glad I could help. |
| ||
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 |
| ||
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 |