News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Convert raw hex to string?

Started by asmftw, September 27, 2007, 02:10:00 AM

Previous topic - Next topic

asmftw

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 :(

askm

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.


MichaelW

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. These procedures are 16-bit code, but the same concepts are applicable to 32-bit code.
eschew obfuscation

asmftw

Thank you I'll use those macros. I used a jmp before but macros are more efficient.

askm

Correction

The line should have read

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

or error


asmftw

you could process each number as a byte and add 30 :)