The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: asmftw on September 27, 2007, 02:10:00 AM

Title: Convert raw hex to string?
Post by: asmftw on September 27, 2007, 02:10:00 AM
Hey how can I convert a raw hex number such as 01h to '1'? I've looked everywhere but I can't find anything about it :(
Title: Re: Convert raw hex to string?
Post by: askm on September 27, 2007, 03:38:02 AM
Cannot you construct a simple

"jump table"

e.g.

with byte ptr's...?

Each byte...
0,1,2,3,4,5,6,7,8,9
would point to...
30,31,32,33,34,35,36,37,38.39

Just a suggest to help you.

Title: Re: Convert raw hex to string?
Post by: MichaelW on September 27, 2007, 03:55:27 AM
asmftw,

If by "raw hex" you mean a value stored in a register or memory, there have been multiple methods posted here, and there are at least five in the MASM32 library. The methods differ depending on the base of the string, typically 2, 10, or 16, and range from easy to understand and slow to difficult to understand and fast. In the MASM32 library see:

dwtoa
dw2hex
dw2ah
udw2str
ltoa (actually a wrapper for wsprintfA)

For easy to understand and slow see the dw2dec, dw2hex, and b2bin procedures in the support module available  here (http://www.masm32.com/board/index.php?topic=7270.msg53765#msg53765). These procedures are 16-bit code, but the same concepts are applicable to 32-bit code.
Title: Re: Convert raw hex to string?
Post by: asmftw on September 27, 2007, 08:43:24 PM
Thank you I'll use those macros. I used a jmp before but macros are more efficient.
Title: Re: Convert raw hex to string?
Post by: askm on September 27, 2007, 10:14:12 PM
Correction

The line should have read

30,31,32,33,34,35,36,37,38,39

or error

Title: Re: Convert raw hex to string?
Post by: asmftw on September 28, 2007, 01:57:02 PM
you could process each number as a byte and add 30 :)