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
Convert HEX to Dezimal ??
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
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)
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)
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Schlowski.
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
Hi 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
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
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
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$)
PB - Registered PureBasic Coder
Edited by - PB on 25 March 2002 19:43:08
> 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
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm