Page 1 of 1
Posted: Mon Mar 25, 2002 2:36 pm
by BackupUser
Restored from previous forum. Originally posted by skypa.
Hi,
i need to convert a hexdezimal string, for example "6C" to a Dezimal Value. Any Ideas how to do this with PureBasic? (Inline ASM tipps are welcome, as long as they are copy&paste&runable
)
thx in advance
skypa
Posted: Mon Mar 25, 2002 3:15 pm
by BackupUser
Restored from previous forum. Originally posted by Paul.
There is a code snippet on the PB Resources Site to do this called HEXDEC...
http://www.reelmediaproductions.com/pb
As well as on this forum, just do a search.
(it's been discussed before)
Posted: Mon Mar 25, 2002 3:16 pm
by BackupUser
Restored from previous forum. Originally posted by Schlowski.
Hi,
i need to convert a hexdezimal string, for example "6C" to a Dezimal Value. Any Ideas how to do this with PureBasic? (Inline ASM tipps are welcome, as long as they are copy&paste&runable
)
thx in advance
skypa
Hi Skypa,
here a little "pure" PureBasic example of how to do it, it's not optimized and has no error-checking and will only convert upper case correct... But it's a beginning
Procedure.l Hex2Long (Hex.s)
Erg.l=0
For i.l=1 To Len(Hex)
c.l = Asc(Mid(Hex,i,1))
If c>64
c - 55
EndIf
If c>47
c - 48
EndIf
Erg = Erg << 4 + c
Next
ProcedureReturn Erg
EndProcedure
OpenConsole()
PrintN (Str(Hex2Long("6C")))
a.s = Input()
CloseConsole()
Schlowski
Posted: Mon Mar 25, 2002 3:17 pm
by BackupUser
Restored from previous forum. Originally posted by Schlowski.
Hey, cut and paste kills my indentation - hopfully you get the idea nevertheless.
Posted: Mon Mar 25, 2002 3:34 pm
by BackupUser
Restored from previous forum. Originally posted by skypa.
Thanks you guys, that was a big help
For later problems I'll use the searchengine before, sorry.
skypa
Posted: Mon Mar 25, 2002 7:40 pm
by BackupUser
Restored from previous forum. Originally posted by PB.
> i need to convert a hexdezimal string, for example "6C" to a Dezimal Value.
Here's what I use, and it can accept mixed-case hex from 0 to FFFFFFF.
To use it, simply call it like so: dec.l=hex2dec(hex$)
Code: Select all
Procedure.l hex2dec(h$)
; h$ can be 0-FFFFFFF.
h$=UCase(h$)
For r=1 To Len(h$)
d60
d+Asc(a$)-55
Else
d+Asc(a$)-48
EndIf
Next
ProcedureReturn d
EndProcedure
PB - Registered PureBasic Coder
Edited by - PB on 25 March 2002 19:43:08
Posted: Mon Mar 25, 2002 7:45 pm
by BackupUser
Restored from previous forum. Originally posted by PB.
> Hey, cut and paste kills my indentation
Next time, surround your code examples with and .
Note: Use square braces, [ and ], and NOT as shown.
PB - Registered PureBasic Coder