It is currently Mon Aug 19, 2019 4:00 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject:
PostPosted: Mon Mar 25, 2002 2:36 pm 
Offline
PureBasic Guru
PureBasic Guru

Joined: Tue Apr 22, 2003 7:42 pm
Posts: 16777133
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 :D )


thx in advance


skypa


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Mar 25, 2002 3:15 pm 
Offline
PureBasic Guru
PureBasic Guru

Joined: Tue Apr 22, 2003 7:42 pm
Posts: 16777133
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)


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Mar 25, 2002 3:16 pm 
Offline
PureBasic Guru
PureBasic Guru

Joined: Tue Apr 22, 2003 7:42 pm
Posts: 16777133
Restored from previous forum. Originally posted by Schlowski.

Quote:
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 :D )


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


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Mar 25, 2002 3:17 pm 
Offline
PureBasic Guru
PureBasic Guru

Joined: Tue Apr 22, 2003 7:42 pm
Posts: 16777133
Restored from previous forum. Originally posted by Schlowski.

Hey, cut and paste kills my indentation - hopfully you get the idea nevertheless.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Mar 25, 2002 3:34 pm 
Offline
PureBasic Guru
PureBasic Guru

Joined: Tue Apr 22, 2003 7:42 pm
Posts: 16777133
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


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Mar 25, 2002 7:40 pm 
Offline
PureBasic Guru
PureBasic Guru

Joined: Tue Apr 22, 2003 7:42 pm
Posts: 16777133
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:
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


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Mar 25, 2002 7:45 pm 
Offline
PureBasic Guru
PureBasic Guru

Joined: Tue Apr 22, 2003 7:42 pm
Posts: 16777133
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


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye