News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

2 questions

Started by kroz, June 02, 2012, 08:58:33 PM

Previous topic - Next topic

kroz

Hi all :) i have 2 questions i would like to know the answer to -

1. How do I convert ASCII input ( 1234567890abcdef) to Hex?
   I mean, something like this : input - 64 (ascii) and convert to 064h ( hex) ?

2. Are there any tutorials on creating a starfield in DIB ?

thanks :)

kroz

00ps, posted two threads :P

dedndave

i see this misconception a lot with newbies...

hexidecimal is a form that we often use to express binary values

so, if you really want to convert from ASCII decimal to ASCII hex, it's a 2-step process
although, i suppose a direct conversion routine could be written
first, you convert ASCII decimal to binary
then, convert binary to ASCII hexidecimal

the masm32 library has a function named "atol" to convert an ASCII decimal string to a binary DWORD value
and another function named "dw2hex" to convert a binary DWORD value into an ASCII hexidecimal string
there are also macros that may be used to simplify the code to call these functions

in the masm32\help folder...
hlhelp.chm describes the macros
masmlib.chm describes the functions

FORTRANS

Quote from: kroz on June 02, 2012, 08:58:33 PM
1. How do I convert ASCII input ( 1234567890abcdef) to Hex?
   I mean, something like this : input - 64 (ascii) and convert to 064h ( hex) ?

Hi,

   Well you will start by deciding how you input your
ASCII hexadecimal string.  (One character at a time or
a complete string?)  Then convert an ASCII character to
a binary value.  For example you could use a lookup table.


; - - - ReadInput - - -
HEX2BIN     DB  48 DUP (-1), 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 6 DUP (-1)
            DB  -1, 10, 11, 12, 13, 14, 15, 9 DUP(-1), 16 DUP(-1)
            DB  -1, 10, 11, 12, 13, 14, 15, 9 DUP(-1), 16 DUP(-1)
            DB  128 DUP(-1)


Here valid hexadecimal ASCII codes are converted to
binary and invalid codes are minus one.

   You can also convert codes with a compare and modify
algorithm if you prefer.

   Then convert another digit to binary, multiply one value
by sixteen and add the two values to get a binary byte
value.  More or less repeat, as needed, for word or double
word values.

Cheers,

Steve N.