Author Topic: 2 questions  (Read 5724 times)

kroz

  • Guest
2 questions
« on: June 02, 2012, 08:58:33 PM »
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

  • Guest
Re: 2 questions
« Reply #1 on: June 02, 2012, 09:03:43 PM »
00ps, posted two threads :P

dedndave

  • Member
  • *****
  • Posts: 8829
  • Still using Abacus 2.0
    • DednDave
Re: 2 questions
« Reply #2 on: June 02, 2012, 10:00:46 PM »
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

  • Member
  • *****
  • Posts: 1136
Re: 2 questions
« Reply #3 on: June 02, 2012, 11:18:43 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.

Code: [Select]
; - - - 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.