# PureBasic Forum

 It is currently Sat Dec 05, 2020 4:42 pm

 All times are UTC + 1 hour

 Page 1 of 1 [ 7 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: Posted: Mon Mar 25, 2002 2:36 pm
 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 )

skypa

Top

 Post subject: Posted: Mon Mar 25, 2002 3:15 pm
 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

 Post subject: Posted: Mon Mar 25, 2002 3:16 pm
 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 )

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

 Post subject: Posted: Mon Mar 25, 2002 3:17 pm
 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

 Post subject: Posted: Mon Mar 25, 2002 3:34 pm
 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

 Post subject: Posted: Mon Mar 25, 2002 7:40 pm
 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

 Post subject: Posted: Mon Mar 25, 2002 7:45 pm
 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

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 7 posts ]

 All times are UTC + 1 hour

#### Who is online

Users browsing this forum: No registered users and 12 guests

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

Search for:
 Jump to:  Select a forum ------------------ PureBasic    Coding Questions    Game Programming    3D Programming    Assembly Programming    The PureBasic Editor    The PureBasic Form Designer    General Discussion    Feature Requests and Wishlists    Tricks 'n' Tips Bug Reports    Bugs - Windows    Bugs - Linux    Bugs - Mac OSX    Bugs - IDE    Bugs - Documentation OS Specific    AmigaOS    Linux    Windows    Mac OSX Miscellaneous    Announcement    Off Topic Showcase    Applications - Feedback and Discussion    PureFORM & JaPBe    TailBite